/* ==========================================================================
   EXTENDDASH - 2026 Flat Design System
   Bento Grid Dashboard / Ultra-minimal / No charts
   ========================================================================== */

/* --- Design Tokens --- */
:root {
  /* Palette - Light */
  --color-bg:          #F7F8FA;
  --color-surface:     #FFFFFF;
  --color-surface-alt: #F0F1F4;
  --color-border:      #E4E6EB;
  --color-text:        #1A1D26;
  --color-text-secondary: #6B7080;
  --color-text-muted:  #9CA3B0;

  /* Accent */
  --color-primary:     #4F6EF7;
  --color-primary-soft:#EEF1FE;
  --color-secondary:   #10B981;
  --color-secondary-soft:#ECFDF5;

  /* Status */
  --color-danger:      #EF4444;
  --color-danger-soft: #FEF2F2;
  --color-warning:     #F59E0B;
  --color-warning-soft:#FFFBEB;
  --color-info:        #3B82F6;
  --color-info-soft:   #EFF6FF;

  /* Spacing scale (4px base) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Shadows (ultra-soft) */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg:  0 4px 16px rgba(0,0,0,0.08);
  --shadow-hover: 0 6px 24px rgba(0,0,0,0.10);

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;

  --text-xs:  0.75rem;
  --text-sm:  0.8125rem;
  --text-base: 0.875rem;
  --text-md:  1rem;
  --text-lg:  1.125rem;
  --text-xl:  1.5rem;
  --text-2xl: 2rem;
  --text-3xl: 2.5rem;

  /* Sidebar */
  --sidebar-width: 64px;
  --sidebar-expanded: 220px;
  --header-height: 60px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --color-bg:          #0F1117;
  --color-surface:     #1A1D28;
  --color-surface-alt: #232636;
  --color-border:      #2E3248;
  --color-text:        #E8E9ED;
  --color-text-secondary: #9CA3B0;
  --color-text-muted:  #5E6370;

  --color-primary-soft:#1E2540;
  --color-secondary-soft:#0F2922;
  --color-danger-soft: #2A1215;
  --color-warning-soft:#2A2010;
  --color-info-soft:   #121E33;

  --shadow-sm:  0 1px 2px rgba(0,0,0,0.20);
  --shadow-md:  0 2px 8px rgba(0,0,0,0.30);
  --shadow-lg:  0 4px 16px rgba(0,0,0,0.35);
  --shadow-hover: 0 6px 24px rgba(0,0,0,0.40);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  transition: background var(--duration-normal) var(--ease-out),
              color var(--duration-normal) var(--ease-out);
}

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

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

/* ==========================================================================
   LAYOUT
   ========================================================================== */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-4) 0;
  z-index: 100;
  transition: width var(--duration-normal) var(--ease-out),
              box-shadow var(--duration-normal) var(--ease-out);
}

.sidebar:hover {
  width: var(--sidebar-expanded);
  box-shadow: var(--shadow-lg);
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: var(--text-lg);
  margin-bottom: var(--sp-8);
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: 0 var(--sp-3);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  transition: background var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
  cursor: pointer;
  text-decoration: none;
}

.sidebar-link i {
  font-size: 1.2rem;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-link span {
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
}

.sidebar:hover .sidebar-link span {
  opacity: 1;
}

.sidebar-link:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.sidebar-link.active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.sidebar-divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--sp-3) var(--sp-3);
}

.sidebar-bottom {
  width: 100%;
  padding: 0 var(--sp-3);
  margin-top: auto;
}

/* --- Main Content --- */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--duration-normal) var(--ease-out);
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-8);
  z-index: 50;
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.85);
}

[data-theme="dark"] .header {
  background: rgba(26,29,40,0.85);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.header-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
}

.header-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.header-breadcrumb span { color: var(--color-text-secondary); }

/* Search */
.header-search {
  position: relative;
  width: 280px;
}

.header-search input {
  width: 100%;
  height: 38px;
  padding: 0 var(--sp-4) 0 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface-alt);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-family);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

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

.header-search input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.header-search i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.header-search kbd {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-size: 0.65rem;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

/* Header Right */
.header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

.header-icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  transition: background var(--duration-fast) var(--ease-out),
              color var(--duration-fast) var(--ease-out);
}

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

.header-icon-btn .badge-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-danger);
  border: 2px solid var(--color-surface);
}

/* Theme toggle */
.theme-toggle {
  width: 44px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  cursor: pointer;
  position: relative;
  transition: background var(--duration-fast) var(--ease-out);
}

.theme-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-primary);
  transition: transform var(--duration-normal) var(--ease-out);
}

[data-theme="dark"] .theme-toggle::after {
  transform: translateX(20px);
}

/* Avatar */
.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary), #8B5CF6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out);
}

.header-avatar:hover {
  transform: scale(1.05);
}

/* Primary button */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5);
  height: 38px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              opacity var(--duration-fast) var(--ease-out);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79,110,247,0.35);
}

.btn-primary:active {
  transform: translateY(0);
  opacity: 0.9;
}

/* ==========================================================================
   CONTENT AREA
   ========================================================================== */

.content {
  padding: var(--sp-8);
  max-width: 1400px;
}

/* Page heading */
.page-heading {
  margin-bottom: var(--sp-8);
}

.page-heading h1 {
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: var(--sp-1);
}

.page-heading p {
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
}

/* ==========================================================================
   BENTO GRID
   ========================================================================== */

.bento-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: auto;
  gap: var(--sp-6);
}

/* Span utilities */
.col-span-1 { grid-column: span 1; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }
.col-span-4 { grid-column: span 4; }

/* ==========================================================================
   CARD (Base component)
   ========================================================================== */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  transition: box-shadow var(--duration-normal) var(--ease-out),
              transform var(--duration-normal) var(--ease-out);
}

.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-5);
}

.card-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-action {
  font-size: var(--text-xs);
  color: var(--color-primary);
  font-weight: 500;
  cursor: pointer;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  transition: background var(--duration-fast) var(--ease-out);
}

.card-action:hover {
  background: var(--color-primary-soft);
}

/* ==========================================================================
   KPI CARDS
   ========================================================================== */

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.kpi-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
}

.kpi-icon.primary {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.kpi-icon.success {
  background: var(--color-secondary-soft);
  color: var(--color-secondary);
}

.kpi-icon.warning {
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.kpi-icon.danger {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.kpi-value {
  font-size: var(--text-3xl);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--color-text);
}

.kpi-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
}

.kpi-change {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px var(--sp-2);
  border-radius: var(--radius-full);
}

.kpi-change.up {
  color: var(--color-secondary);
  background: var(--color-secondary-soft);
}

.kpi-change.down {
  color: var(--color-danger);
  background: var(--color-danger-soft);
}

.kpi-footer {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ==========================================================================
   ACTIVITY FEED
   ========================================================================== */

.activity-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--color-border);
  transition: background var(--duration-fast) var(--ease-out);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-item:hover {
  background: var(--color-surface-alt);
  margin: 0 calc(var(--sp-3) * -1);
  padding-left: var(--sp-3);
  padding-right: var(--sp-3);
  border-radius: var(--radius-sm);
}

.activity-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.activity-icon.blue   { background: var(--color-info-soft);   color: var(--color-info); }
.activity-icon.green  { background: var(--color-secondary-soft); color: var(--color-secondary); }
.activity-icon.orange { background: var(--color-warning-soft); color: var(--color-warning); }
.activity-icon.red    { background: var(--color-danger-soft);  color: var(--color-danger); }

.activity-content {
  flex: 1;
  min-width: 0;
}

.activity-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  line-height: 1.4;
}

.activity-title strong {
  font-weight: 600;
}

.activity-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ==========================================================================
   BADGE / TAG
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-primary  { background: var(--color-primary-soft);   color: var(--color-primary); }
.badge-success  { background: var(--color-secondary-soft); color: var(--color-secondary); }
.badge-warning  { background: var(--color-warning-soft);   color: var(--color-warning); }
.badge-danger   { background: var(--color-danger-soft);    color: var(--color-danger); }
.badge-info     { background: var(--color-info-soft);      color: var(--color-info); }
.badge-neutral  { background: var(--color-surface-alt);    color: var(--color-text-secondary); }

/* ==========================================================================
   TASKS / PIPELINE TABLE
   ========================================================================== */

.task-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.task-table thead th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
}

.task-table tbody td {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.task-table tbody tr {
  transition: background var(--duration-fast) var(--ease-out);
}

.task-table tbody tr:hover {
  background: var(--color-surface-alt);
}

.task-table tbody tr:last-child td {
  border-bottom: none;
}

.task-name {
  font-weight: 500;
}

.task-assignee {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.task-assignee-avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #8B5CF6, var(--color-primary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
}

.task-priority {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.task-priority.high    { background: var(--color-danger); }
.task-priority.medium  { background: var(--color-warning); }
.task-priority.low     { background: var(--color-secondary); }

/* ==========================================================================
   NOTIFICATIONS / EVENTS
   ========================================================================== */

.notif-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.notif-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--color-border);
  transition: background var(--duration-fast) var(--ease-out);
}

.notif-item:last-child {
  border-bottom: none;
}

.notif-item:hover {
  background: var(--color-surface-alt);
  margin: 0 calc(var(--sp-3) * -1);
  padding-left: var(--sp-3);
  padding-right: var(--sp-3);
  border-radius: var(--radius-sm);
}

.notif-item.unread {
  position: relative;
}

.notif-item.unread::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
}

.notif-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.notif-content {
  flex: 1;
  min-width: 0;
}

.notif-text {
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: 1.4;
}

.notif-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.notif-priority {
  flex-shrink: 0;
}

/* ==========================================================================
   QUICK STATS ROW (mini inline KPIs)
   ========================================================================== */

.quick-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-6);
  padding: var(--sp-4) 0;
}

.quick-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.quick-stat-value {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--color-text);
}

.quick-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ==========================================================================
   TIMELINE
   ========================================================================== */

.timeline {
  position: relative;
  padding-left: var(--sp-6);
}

.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-border);
  border-radius: 1px;
}

.timeline-item {
  position: relative;
  padding-bottom: var(--sp-5);
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: calc(var(--sp-6) * -1 + 3px);
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--color-primary);
  background: var(--color-surface);
}

.timeline-dot.done {
  background: var(--color-primary);
}

.timeline-time {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.timeline-text {
  font-size: var(--text-sm);
  color: var(--color-text);
  font-weight: 500;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

/* ── Desktop 1200 ── */
@media (max-width: 1200px) {
  .bento-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .col-span-3 { grid-column: span 2; }
  .col-span-4 { grid-column: span 2; }
}

/* ── Tablet 768 ── */
@media (max-width: 768px) {
  .sidebar {
    width: 0;
    overflow: hidden;
    transition: width var(--duration-normal) var(--ease-out);
  }
  .sidebar.open {
    width: var(--sidebar-expanded);
  }
  /* On mobile, sidebar always shows labels when open */
  .sidebar.open .sidebar-link span {
    opacity: 1;
  }
  .main-wrapper {
    margin-left: 0;
  }
  .bento-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-4);
  }
  .col-span-2,
  .col-span-3,
  .col-span-4 { grid-column: span 1; }
  .content {
    padding: var(--sp-4);
  }
  .header {
    padding: 0 var(--sp-4);
  }
  .header-search {
    display: none;
  }
  .header-breadcrumb {
    display: none;
  }

  /* Page toolbar stacks */
  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .page-toolbar-right {
    flex-wrap: wrap;
  }
  .search-input {
    flex: 1;
    min-width: 0;
  }
  .search-input input {
    width: 100%;
  }

  /* Form rows go single column */
  .form-row {
    grid-template-columns: 1fr;
  }

  /* Modal full-width on tablet */
  .modal {
    width: 95%;
    max-height: 90vh;
    border-radius: var(--radius-lg);
  }
  .modal-header {
    padding: var(--sp-4) var(--sp-5);
  }
  .modal-body {
    padding: var(--sp-4) var(--sp-5);
  }
  .modal-footer {
    padding: var(--sp-3) var(--sp-5);
  }
  .modal-close {
    width: 44px;
    height: 44px;
  }

  /* Cards reduce padding */
  .card {
    padding: var(--sp-4);
  }

  /* KPI value scales down */
  .kpi-value {
    font-size: var(--text-2xl);
  }

  /* Table compact padding */
  .data-table thead th,
  .data-table tbody td,
  .task-table thead th,
  .task-table tbody td {
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--text-xs);
  }

  /* Table scroll hint gradient */
  .data-table-wrapper {
    position: relative;
  }
  .data-table-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to left, var(--color-surface) 0%, transparent 100%);
    pointer-events: none;
    opacity: 0.8;
  }

  /* Touch-friendly action buttons */
  .table-actions {
    gap: var(--sp-2);
  }
  .btn-icon,
  .btn-icon.btn-sm {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  /* Toast full width */
  .toast-container {
    top: var(--sp-3);
    right: var(--sp-3);
    left: var(--sp-3);
  }
  .toast {
    min-width: 0;
    width: 100%;
  }

  /* Quick stats wrap */
  .quick-stats {
    flex-wrap: wrap;
    gap: var(--sp-4);
  }

  /* Empty state smaller padding */
  .empty-state {
    padding: var(--sp-10) var(--sp-4);
  }

  /* Page heading tighter */
  .page-heading {
    margin-bottom: var(--sp-5);
  }

  /* Pagination touch targets */
  .pagination button {
    width: 40px;
    height: 40px;
  }

  /* Activity/notif hover fix: always visible on touch */
  .activity-item:hover,
  .notif-item:hover {
    margin: 0;
    padding-left: 0;
    padding-right: 0;
  }
}

/* ── Small phone 480 ── */
@media (max-width: 480px) {
  .header-right .btn-primary {
    display: none;
  }
  .header-right {
    gap: var(--sp-2);
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    animation: modalSlideUp var(--duration-normal) var(--ease-out);
  }
  .modal-lg {
    max-width: 100%;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--color-surface);
    z-index: 2;
  }

  .kpi-value {
    font-size: var(--text-xl);
  }

  .data-table thead th,
  .data-table tbody td {
    padding: var(--sp-2);
  }

  .page-toolbar-right {
    width: 100%;
  }
  .page-toolbar-right .btn {
    flex: 1;
  }

  /* Content minimal padding */
  .content {
    padding: var(--sp-3);
  }

  .card {
    padding: var(--sp-3);
    border-radius: var(--radius-md);
  }

  .card-header {
    margin-bottom: var(--sp-3);
  }
}

/* ── Tiny phone 360 ── */
@media (max-width: 360px) {
  .header-avatar {
    display: none;
  }
  .kpi-value {
    font-size: var(--text-lg);
  }
  .modal-header {
    padding: var(--sp-3) var(--sp-4);
  }
  .modal-body {
    padding: var(--sp-3) var(--sp-4);
  }
  .modal-footer {
    padding: var(--sp-3) var(--sp-4);
  }
}

/* ==========================================================================
   MICRO ANIMATIONS
   ========================================================================== */

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(100%); }
  to { opacity: 1; transform: translateY(0); }
}

/* Disable heavy animations on reduced motion / mobile */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.bento-grid > * {
  animation: fadeInUp var(--duration-slow) var(--ease-out) both;
}

.bento-grid > *:nth-child(1) { animation-delay: 0ms; }
.bento-grid > *:nth-child(2) { animation-delay: 60ms; }
.bento-grid > *:nth-child(3) { animation-delay: 120ms; }
.bento-grid > *:nth-child(4) { animation-delay: 180ms; }
.bento-grid > *:nth-child(5) { animation-delay: 240ms; }
.bento-grid > *:nth-child(6) { animation-delay: 300ms; }
.bento-grid > *:nth-child(7) { animation-delay: 360ms; }
.bento-grid > *:nth-child(8) { animation-delay: 420ms; }

/* Pulse for notification dot */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.badge-dot {
  animation: pulse 2s ease-in-out infinite;
}

/* Number count-up placeholder */
.kpi-value {
  transition: color var(--duration-normal) var(--ease-out);
}

/* Mobile menu toggle */
.mobile-menu-btn {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
  .mobile-menu-btn {
    display: flex;
  }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
  -webkit-tap-highlight-color: transparent;
}

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

/* ==========================================================================
   BODY SCROLL LOCK (when modal is open)
   ========================================================================== */

body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* ==========================================================================
   TOUCH HELPERS
   ========================================================================== */

/* Disable tap highlight everywhere for clean touch */
button, a, .sidebar-link, .header-icon-btn, .theme-toggle, .header-avatar, .card-action {
  -webkit-tap-highlight-color: transparent;
}

/* Ensure touch targets >= 44px on mobile */
@media (max-width: 768px) {
  .header-icon-btn {
    width: 44px;
    height: 44px;
  }
  .theme-toggle {
    width: 50px;
    height: 28px;
  }
  .theme-toggle::after {
    width: 22px;
    height: 22px;
  }
  [data-theme="dark"] .theme-toggle::after {
    transform: translateX(22px);
  }
  .sidebar-link {
    padding: var(--sp-3) var(--sp-3);
    min-height: 44px;
  }
}

/* Long monospace text (IBAN, card numbers) */
.font-mono {
  word-break: break-all;
}

/* Inline flex helpers that always wrap */
.flex-wrap-mobile {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
}

/* ==========================================================================
   FORMS
   ========================================================================== */

.form-group {
  margin-bottom: var(--sp-5);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--sp-2);
}

.form-control {
  width: 100%;
  height: 40px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-family);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.form-control::placeholder {
  color: var(--color-text-muted);
}

textarea.form-control {
  height: auto;
  min-height: 80px;
  padding: var(--sp-3);
  resize: vertical;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7080' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--sp-1);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-top: var(--sp-1);
}

.form-control.is-invalid {
  border-color: var(--color-danger);
}

.form-control.is-invalid:focus {
  box-shadow: 0 0 0 3px var(--color-danger-soft);
}

/* ==========================================================================
   MODAL
   ========================================================================== */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn var(--duration-normal) var(--ease-out);
}

.modal-lg {
  max-width: 780px;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-6);
  border-bottom: 1px solid var(--color-border);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--duration-fast) var(--ease-out);
}

.modal-close:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.modal-body {
  padding: var(--sp-6);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--color-border);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79,110,247,0.35);
}

.btn-secondary {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border-color: var(--color-border);
}

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

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}

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

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

.btn-ghost:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.btn-sm {
  height: 30px;
  padding: 0 var(--sp-3);
  font-size: var(--text-xs);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
}

.btn-icon.btn-sm {
  width: 28px;
  height: 28px;
}

/* ==========================================================================
   DATA TABLE (CRUD listing)
   ========================================================================== */

.data-table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.data-table thead th {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--color-surface);
}

.data-table tbody td {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--duration-fast) var(--ease-out);
}

.data-table tbody tr:hover {
  background: var(--color-surface-alt);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

/* ==========================================================================
   PAGE TOOLBAR
   ========================================================================== */

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
  flex-wrap: wrap;
  gap: var(--sp-3);
}

.page-toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.page-toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.search-input {
  position: relative;
}

.search-input input {
  width: 240px;
  max-width: 100%;
  height: 38px;
  padding: 0 var(--sp-4) 0 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-family);
  outline: none;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.search-input input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.search-input i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */

.toast-container {
  position: fixed;
  top: var(--sp-6);
  right: var(--sp-6);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  min-width: min(280px, 100%);
  animation: toastIn var(--duration-normal) var(--ease-out);
}

.toast.success { border-left: 3px solid var(--color-secondary); }
.toast.error   { border-left: 3px solid var(--color-danger); }
.toast.info    { border-left: 3px solid var(--color-primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ==========================================================================
   EMPTY STATE
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-16) var(--sp-6);
  color: var(--color-text-muted);
  text-align: center;
}

.empty-state i {
  margin-bottom: var(--sp-4);
  opacity: 0.4;
}

.empty-state p {
  font-size: var(--text-sm);
}

/* ==========================================================================
   DETAIL PANEL (for sub-tables like ecard history, orderlines)
   ========================================================================== */

.detail-panel {
  background: var(--color-surface-alt);
  border-radius: var(--radius-md);
  padding: var(--sp-5);
  margin-top: var(--sp-4);
}

.detail-panel .card-title {
  margin-bottom: var(--sp-4);
}

/* ==========================================================================
   PAGINATION
   ========================================================================== */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  margin-top: var(--sp-6);
}

.pagination button {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}

.pagination button:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.pagination button.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==========================================================================
   UTILITY
   ========================================================================== */

.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.font-mono { font-family: var(--font-mono); }
.mt-4 { margin-top: var(--sp-4); }
.mb-4 { margin-bottom: var(--sp-4); }
.gap-2 { gap: var(--sp-2); }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ── Phase 4 add-ons (KPI grid + card body + content layout) ── */
.kpi-grid {
    display: grid; gap: var(--sp-4);
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.kpi-content { display: flex; flex-direction: column; gap: 4px; }
.kpi-trend  { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 4px; }
.card-body  { padding: var(--sp-4) var(--sp-5); }
.card-footer{ padding: var(--sp-3) var(--sp-5) var(--sp-4); border-top: 1px solid var(--color-border); }
.form-grid  { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

@media (max-width: 768px) {
    .settings-grid { grid-template-columns: 1fr !important; }
}
