/* ============================================================
   IMATA Payroll – Layout (shell, sidebar, topbar, content)
   ============================================================ */

/* ── Page wrapper ── */
.page-wrap {
  min-height: 100vh;
  background:
    linear-gradient(135deg, var(--page-bg-from) 0%, var(--page-bg-to) 100%);
  position: relative;
  overflow-x: hidden;
}

/* Decorative arcs on page background */
.page-wrap::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(ellipse 900px 600px at 110% 20%, rgba(247,147,26,.07) 0%, transparent 70%),
    radial-gradient(ellipse 600px 400px at -10% 80%, rgba(15,23,42,.06) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ── App canvas ── */
.app-canvas {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: var(--sidebar-w);
  background: var(--navy-900);
  border-radius: var(--radius-canvas);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow: hidden;
  transition: width 200ms ease-out, transform 200ms ease-out;
  box-shadow: var(--shadow-float);
  border: 1px solid rgba(30,41,59,.6);
}

/* Sidebar header */
.sidebar-header {
  padding: 24px 20px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  background: var(--orange-500);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo svg { width: 20px; height: 20px; }

.sidebar-brand {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand-name {
  font-size: 14px;
  font-weight: 700;
  color: #FFFFFF;
  white-space: nowrap;
  letter-spacing: .3px;
}

.sidebar-brand-sub {
  font-size: 11px;
  color: rgba(255,255,255,.45);
  white-space: nowrap;
}

/* Nav section label */
.nav-label {
  padding: 16px 20px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: rgba(255,255,255,.3);
  white-space: nowrap;
  overflow: hidden;
}

/* Nav list */
.nav-list {
  list-style: none;
  padding: 0 12px;
}

.nav-item {
  margin-bottom: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-control);
  color: rgba(255,255,255,.6);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 150ms, color 150ms;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
}

.nav-link:hover {
  background: rgba(255,255,255,.07);
  color: #FFFFFF;
}

.nav-link.active {
  background: rgba(247,147,26,.12);
  color: #FFFFFF;
}

/* Orange left indicator on active */
.nav-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--orange-500);
  border-radius: 0 3px 3px 0;
}

.nav-link .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-link .nav-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-link .nav-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  background: var(--orange-500);
  color: var(--navy-900);
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  flex-shrink: 0;
}

/* Sidebar divider */
.sidebar-divider {
  height: 1px;
  background: rgba(255,255,255,.08);
  margin: 12px 20px;
  flex-shrink: 0;
}

/* Sidebar scroll area */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.12) transparent;
}

/* Cut-off card at bottom of sidebar */
.sidebar-cutoff-card {
  margin: 12px;
  background: rgba(247,147,26,.12);
  border: 1px solid rgba(247,147,26,.25);
  border-radius: var(--radius-card);
  padding: 16px;
  flex-shrink: 0;
}

.sidebar-cutoff-card .cutoff-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--orange-500);
  margin-bottom: 6px;
}

.sidebar-cutoff-card .cutoff-days {
  font-size: 28px;
  font-weight: 700;
  color: #FFFFFF;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.sidebar-cutoff-card .cutoff-days span {
  font-size: 13px;
  font-weight: 400;
  color: rgba(255,255,255,.5);
  margin-left: 4px;
}

.sidebar-cutoff-card .cutoff-period {
  font-size: 12px;
  color: rgba(255,255,255,.5);
  margin-top: 4px;
  margin-bottom: 14px;
}

.sidebar-cutoff-card .btn-open-payroll {
  display: block;
  width: 100%;
  text-align: center;
  padding: 9px;
  background: var(--orange-500);
  color: var(--navy-900);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-control);
  text-decoration: none;
  transition: background 150ms;
}

.sidebar-cutoff-card .btn-open-payroll:hover {
  background: var(--orange-600);
}

/* ── Top bar ── */
.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: calc(var(--sidebar-w) + 32px + 24px);
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 32px;
  z-index: 100;
  background: transparent;
  transition: left 200ms ease-out;
}

/* Search */
.topbar-search {
  flex: 1;
  max-width: 400px;
}

.topbar-search-inner {
  position: relative;
}

.topbar-search-inner svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 1.75;
  pointer-events: none;
}

.topbar-search input {
  width: 100%;
  height: 40px;
  padding: 0 16px 0 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  transition: border-color 150ms, box-shadow 150ms;
}

.topbar-search input::placeholder { color: var(--text-muted); }

.topbar-search input:focus {
  border-color: var(--orange-500);
  box-shadow: 0 0 0 3px rgba(247,147,26,.15);
  outline: none;
}

.topbar-spacer { flex: 1; }

/* Segmented control – Light/Dark */
.seg-control {
  display: flex;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  height: 32px;
  padding: 0 12px;
  border: none;
  background: none;
  border-radius: calc(var(--radius-control) - 3px);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 150ms, color 150ms;
  white-space: nowrap;
}

.seg-btn svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
}

.seg-btn.active,
.seg-btn[aria-pressed="true"] {
  background: var(--navy-900);
  color: #FFFFFF;
}

[data-theme="dark"] .seg-btn.active,
[data-theme="dark"] .seg-btn[aria-pressed="true"] {
  background: var(--orange-500);
  color: var(--navy-900);
}

/* Month selector */
.month-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0 4px;
  height: 40px;
}

.month-selector button {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background 150ms;
}

.month-selector button:hover { background: var(--surface-muted); }

.month-selector button svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.month-selector .month-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  min-width: 120px;
  text-align: center;
}

/* Bell */
.topbar-bell {
  position: relative;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-control);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background 150ms, color 150ms;
}

.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  background: var(--orange-500);
  color: var(--navy-900);
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--canvas);
}

/* Profile */
.topbar-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-control);
  transition: background 150ms;
}

.topbar-profile:hover { background: var(--surface-muted); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--navy-900);
  color: #FFF;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: .5px;
}

.avatar.orange { background: var(--orange-500); color: var(--navy-900); }

.profile-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.profile-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.profile-role {
  font-size: 11px;
  color: var(--text-muted);
}

.topbar-profile svg.chevron {
  width: 14px;
  height: 14px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 2;
}

/* DEMO badge */
.demo-badge {
  background: var(--orange-50);
  color: var(--orange-700);
  border: 1px solid rgba(247,147,26,.3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .8px;
  padding: 3px 8px;
  border-radius: var(--radius-chip);
  text-transform: uppercase;
}

/* ── Main content area ── */
.main-content {
  margin-left: calc(var(--sidebar-w) + 32px);
  padding-top: var(--topbar-h);
  min-height: 100vh;
  transition: margin-left 200ms ease-out;
}

.content-inner {
  padding: 32px;
  max-width: 1400px;
}

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
}

.page-title-group {}

.page-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Grid ── */
.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 24px;
}

.col-3  { grid-column: span 3; }
.col-4  { grid-column: span 4; }
.col-6  { grid-column: span 6; }
.col-8  { grid-column: span 8; }
.col-9  { grid-column: span 9; }
.col-12 { grid-column: span 12; }

/* ── Responsive ── */

/* Tablet (768–1279px): sidebar collapses to icon rail */
@media (max-width: 1279px) and (min-width: 768px) {
  :root { --sidebar-w: var(--sidebar-collapsed-w); }

  .sidebar-brand,
  .nav-text,
  .nav-label,
  .nav-badge,
  .sidebar-brand-name,
  .sidebar-brand-sub,
  .sidebar-cutoff-card .cutoff-label,
  .sidebar-cutoff-card .cutoff-days,
  .sidebar-cutoff-card .cutoff-period,
  .sidebar-cutoff-card .btn-open-payroll {
    display: none;
  }

  .sidebar {
    align-items: center;
    border-radius: var(--radius-card);
    overflow: visible; /* allow tooltips */
  }

  .nav-list { padding: 0 8px; }

  .nav-link {
    padding: 10px;
    justify-content: center;
  }

  /* No left indicator in icon-rail mode */
  .nav-link::before { display: none; }

  /* Active item: orange icon instead */
  .nav-link.active .nav-icon svg { stroke: var(--orange-500); }

  .sidebar-header { justify-content: center; padding: 20px 0; }
  .sidebar-cutoff-card { padding: 10px; min-height: 44px; }

  /* Grid adjustments for tablet */
  .col-3 { grid-column: span 6; }
  .col-4 { grid-column: span 6; }
  .col-9 { grid-column: span 12; }
}

/* ── Topbar responsive ── */
@media (max-width: 1279px) and (min-width: 768px) {
  .topbar {
    left: calc(var(--sidebar-collapsed-w) + 32px + 24px);
  }
  .main-content {
    margin-left: calc(var(--sidebar-collapsed-w) + 32px);
  }
}

/* Tablet: condense topbar */
@media (max-width: 900px) and (min-width: 768px) {
  .topbar-search { max-width: 180px; }
  .profile-text  { display: none; }
  .topbar-profile { padding: 4px; }
}

/* Mobile: full-width topbar with menu toggle */
@media (max-width: 767px) {
  .topbar {
    left: 0 !important;
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-search  { display: none; }
  .topbar-spacer  { display: none; }
  .month-selector .month-label { min-width: 80px; font-size: 11px; }
  .month-selector { padding: 0 2px; }
  .demo-badge     { display: none; }
  .profile-text   { display: none; }
  .topbar-profile { padding: 4px; border: 1px solid var(--border); }
  .seg-btn span   { display: none; }
  .seg-btn        { padding: 0 8px; }
}

/* Tables scroll horizontally on mobile */
@media (max-width: 900px) {
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .data-table th,
  .data-table td { white-space: nowrap; }
}

@media (max-width: 767px) {
  /* Override collapsed-rail styles for mobile */
  :root { --sidebar-w: 272px; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 272px;
    border-radius: 0;
    transform: translateX(-110%);
    transition: transform 220ms ease-out;
  }

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

  /* Restore full sidebar content on mobile */
  .sidebar-brand            { display: flex; flex-direction: column; }
  .sidebar-brand-name       { display: block; }
  .sidebar-brand-sub        { display: block; }
  .nav-text                 { display: block; }
  .nav-label                { display: block; }
  .nav-badge                { display: flex; }
  .sidebar-cutoff-card .cutoff-label  { display: block; }
  .sidebar-cutoff-card .cutoff-days   { display: block; }
  .sidebar-cutoff-card .cutoff-period { display: block; }
  .sidebar-cutoff-card .btn-open-payroll { display: block; }

  /* Restore left indicator on active nav item */
  .nav-link { padding: 10px 12px; justify-content: flex-start; }
  .nav-link.active::before { display: block; }

  /* Sidebar header back to full layout */
  .sidebar-header { justify-content: flex-start; padding: 24px 20px 20px; }

  /* Topbar takes full width */
  .topbar {
    left: 0;
    padding: 0 16px;
    gap: 10px;
  }

  /* Hide search on very small screens to save space */
  .topbar-search { display: none; }

  /* Shrink topbar items */
  .month-selector .month-label { min-width: 90px; font-size: 12px; }
  .demo-badge { display: none; }

  /* Content takes full width */
  .main-content {
    margin-left: 0;
    padding-top: var(--topbar-h);
  }

  .content-inner { padding: 16px; }

  /* All grid columns go full width on mobile */
  .col-3, .col-4, .col-6, .col-8, .col-9, .col-12 {
    grid-column: span 12;
  }

  /* Sidebar overlay backdrop */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 190;
  }
}
