/* ============================================================
   eFin RoboLab — Shell Layout (shell.css)
   Version: 1.1
   Reference: layer1_technical_decisions_v1.1.md Section 8
   Depends on: variables.css

   Layout:
   ┌─────────────────────────────────────────┐
   │  Header (56px, fixed top)                │
   ├──────────┬──────────────────────────────┤
   │ Sidebar  │  Content Area                 │
   │ (220px)  │  (scrollable)                 │
   │ (fixed)  │                               │
   └──────────┴──────────────────────────────┘

   Mobile (< 768px):
   ┌─────────────────────┐
   │  Header (56px)       │
   ├─────────────────────┤
   │  Content (full)      │
   ├─────────────────────┤
   │  Bottom Nav (56px)   │
   └─────────────────────┘
   ============================================================ */

/* ──────────────────────────────────────────────
   RESET + BASE
   ────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  color: var(--color-text);
  background: var(--color-bg);
  overflow: hidden; /* shell จัดการ scroll เอง */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  color: var(--color-primary-hover);
}

button {
  font-family: var(--font-family);
  cursor: pointer;
  border: none;
  background: none;
  font-size: inherit;
  color: inherit;
}


/* ──────────────────────────────────────────────
   APP SHELL — overall grid
   ────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas:
    "header  header"
    "sidebar content";
  height: 100vh;
  width: 100vw;
}


/* ──────────────────────────────────────────────
   HEADER
   ────────────────────────────────────────────── */
.header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--spacing-4);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  z-index: var(--z-header);
  position: sticky;
  top: 0;
}

/* Left: Logo + Brand */
.header__left {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
}

.header__menu-btn {
  display: none; /* ซ่อนบน desktop, แสดงบน mobile */
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: background var(--transition-fast);
}

.header__menu-btn:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}

.header__logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  object-fit: contain;
}

/* Placeholder logo (ใช้ก่อน มี logo จริง) */
.header__logo-placeholder {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-inverse);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  flex-shrink: 0;
}

.header__brand {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

/* Right: Quota + Notification + Theme + Avatar */
.header__right {
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
}

/* Quota display */
.header__quota {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-size: var(--font-size-xs);
  color: var(--color-quota-normal);
  padding: var(--spacing-1) var(--spacing-2);
  border-radius: var(--radius-sm);
  background: var(--color-bg-secondary);
}

.header__quota.warning {
  color: var(--color-quota-warning);
  background: var(--color-warning-subtle);
}

.header__quota.critical {
  color: var(--color-quota-critical);
  background: var(--color-danger-subtle);
}

.header__quota-used {
  font-weight: var(--font-weight-semibold);
}

.header__quota-label {
  color: var(--color-text-hint);
  margin-left: 2px;
}

/* Notification bell */
.header__notification {
  position: relative;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}

.header__notification:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}

.header__notification-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-danger);
  border: 2px solid var(--color-bg);
}

/* Theme toggle */
.header__theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
}

.header__theme-toggle:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}

/* Role badge */
.header__role-badge {
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-medium);
  padding: 2px var(--spacing-2);
  border-radius: var(--radius-sm);
  background: var(--color-primary-subtle);
  color: var(--color-primary);
  white-space: nowrap;
}

/* Avatar */
.header__avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--color-bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: box-shadow var(--transition-fast);
}

.header__avatar:hover {
  box-shadow: 0 0 0 2px var(--color-border-focus);
}


/* ──────────────────────────────────────────────
   SIDEBAR
   ────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  width: var(--sidebar-width);
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--spacing-3) 0;
  z-index: var(--z-sidebar);
}

/* Scrollbar styling */
.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-hover);
}

/* Menu group */
.sidebar__group {
  margin-bottom: var(--spacing-4);
}

.sidebar__group-label {
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-hint);
  padding: var(--spacing-1) var(--spacing-4);
  margin-bottom: var(--spacing-1);
}

/* Menu item */
.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--spacing-2);
  padding: var(--spacing-2) var(--spacing-4);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.sidebar__item:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}

.sidebar__item.active {
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  background: var(--color-primary-subtle);
  font-weight: var(--font-weight-medium);
}

.sidebar__item-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar__item.active .sidebar__item-icon {
  opacity: 1;
}

.sidebar__item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Badge count on menu item (e.g. alerts count) */
.sidebar__item-badge {
  font-size: var(--font-size-2xs);
  font-weight: var(--font-weight-semibold);
  min-width: 18px;
  height: 18px;
  padding: 0 var(--spacing-1);
  border-radius: var(--radius-full);
  background: var(--color-danger);
  color: var(--color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sidebar footer (version info, logout) */
.sidebar__footer {
  padding: var(--spacing-3) var(--spacing-4);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}


/* ──────────────────────────────────────────────
   CONTENT AREA
   ────────────────────────────────────────────── */
.content {
  grid-area: content;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--content-padding);
  background: var(--color-bg);
}

.content__inner {
  max-width: var(--max-content-width);
  margin: 0 auto;
}

/* Breadcrumb */
.content__breadcrumb {
  font-size: var(--font-size-xs);
  color: var(--color-text-hint);
  margin-bottom: var(--spacing-1);
}

.content__breadcrumb a {
  color: var(--color-text-hint);
  transition: color var(--transition-fast);
}

.content__breadcrumb a:hover {
  color: var(--color-primary);
}

.content__breadcrumb-separator {
  margin: 0 var(--spacing-1);
}

.content__breadcrumb-current {
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
}

/* Page title */
.content__title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--spacing-5);
  line-height: var(--line-height-tight);
}

/* Page subtitle */
.content__subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-top: calc(var(--spacing-1) * -1);
  margin-bottom: var(--spacing-5);
}

/* Content sections */
.content__section {
  margin-bottom: var(--spacing-6);
}

.content__section-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  margin-bottom: var(--spacing-3);
}

/* Card grid (for dashboard cards) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing-4);
}

/* Base card */
.card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-4);
  transition: box-shadow var(--transition-normal);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card__label {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--spacing-1);
}

.card__value {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  line-height: var(--line-height-tight);
}

/* Placeholder for chart areas */
.chart-placeholder {
  height: 200px;
  background: var(--color-bg-secondary);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-hint);
  font-size: var(--font-size-sm);
}


/* ──────────────────────────────────────────────
   BOTTOM NAV (mobile only)
   ────────────────────────────────────────────── */
.bottom-nav {
  display: none; /* ซ่อนบน desktop */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--color-bg);
  border-top: 1px solid var(--color-border);
  z-index: var(--z-header);
}

.bottom-nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px; /* ตาม Design Guide 1.7 */
  min-height: 44px;
  padding: var(--spacing-1);
  color: var(--color-text-hint);
  font-size: var(--font-size-2xs);
  cursor: pointer;
  transition: color var(--transition-fast);
  border-radius: var(--radius-md);
}

.bottom-nav__item:hover {
  color: var(--color-text-muted);
}

.bottom-nav__item.active {
  color: var(--color-primary);
}

.bottom-nav__item-icon {
  font-size: var(--font-size-xl);
}


/* ──────────────────────────────────────────────
   SIDEBAR OVERLAY (mobile)
   ────────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: calc(var(--z-sidebar) - 1);
}

.sidebar-overlay.visible {
  display: block;
}


/* ──────────────────────────────────────────────
   MODAL BACKDROP
   ────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-backdrop.visible {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--spacing-6);
  max-width: 440px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform var(--transition-normal);
}

.modal-backdrop.visible .modal {
  transform: translateY(0);
}

.modal__title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--spacing-2);
}

.modal__body {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-5);
  line-height: var(--line-height-relaxed);
}

.modal__actions {
  display: flex;
  gap: var(--spacing-3);
  justify-content: flex-end;
}


/* ──────────────────────────────────────────────
   BUTTONS
   ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-2);
  padding: var(--spacing-2) var(--spacing-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  min-height: 36px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--color-bg-secondary);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg-tertiary);
  border-color: var(--color-border-hover);
}

.btn-danger {
  background: var(--color-danger);
  color: var(--color-text-inverse);
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}


/* ──────────────────────────────────────────────
   LOADING STATES
   ────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-secondary) 25%,
    var(--color-bg-tertiary) 50%,
    var(--color-bg-secondary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-pulse {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: var(--spacing-5);
  right: var(--spacing-5);
  padding: var(--spacing-3) var(--spacing-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  transform: translateY(100px);
  opacity: 0;
  transition: all var(--transition-slow);
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.toast-success { background: var(--color-success); color: #fff; }
.toast-danger  { background: var(--color-danger); color: #fff; }
.toast-warning { background: var(--color-warning); color: #fff; }
.toast-info    { background: var(--color-info); color: #fff; }


/* ──────────────────────────────────────────────
   RESPONSIVE — Tablet (768-1024px)
   ────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--spacing-3);
  }
}


/* ──────────────────────────────────────────────
   RESPONSIVE — Mobile (< 768px)
   ────────────────────────────────────────────── */
@media (max-width: 767px) {
  /* Shell grid: ไม่มี sidebar column */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-height) 1fr var(--bottom-nav-height);
    grid-template-areas:
      "header"
      "content"
      "bottomnav";
  }

  /* Header: แสดง hamburger, ซ่อน brand text */
  .header__menu-btn {
    display: flex;
  }

  .header__brand {
    display: none;
  }

  .header__role-badge {
    display: none;
  }

  /* Sidebar: overlay mode */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform var(--transition-slow);
    z-index: var(--z-sidebar);
    padding-top: calc(var(--header-height) + var(--spacing-3));
  }

  .sidebar.open {
    transform: translateX(0);
  }

  /* Content: full width + padding for bottom nav */
  .content {
    padding: var(--content-padding-mobile);
    padding-bottom: calc(var(--bottom-nav-height) + var(--spacing-3));
  }

  .content__title {
    font-size: var(--font-size-xl);
  }

  /* Bottom nav: แสดงบน mobile */
  .bottom-nav {
    display: block;
    grid-area: bottomnav;
  }

  /* Cards: stack */
  .card-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-3);
  }

  /* Modal: full width */
  .modal {
    width: 95%;
    max-height: 85vh;
    padding: var(--spacing-4);
  }

  /* Toast: full width bottom */
  .toast {
    left: var(--spacing-3);
    right: var(--spacing-3);
    bottom: calc(var(--bottom-nav-height) + var(--spacing-3));
  }
}


/* ──────────────────────────────────────────────
   PRINT
   ────────────────────────────────────────────── */
@media print {
  .header,
  .sidebar,
  .bottom-nav {
    display: none;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "content";
  }

  .content {
    overflow: visible;
    padding: 0;
  }
}
