/* ============================================================================
   TiCi Tissue Culture Portal — Design System
   Modern agri-tech theme: deep teal/green primary, warm neutrals, card UI.
   Mobile-first, fully responsive.
   ============================================================================ */

:root {
  --color-primary: #0d6b5f;
  --color-primary-dark: #0a5148;
  --color-primary-light: #e6f2f0;
  --color-accent: #84cc16;
  --color-accent-dark: #65a30d;

  --color-success: #16a34a;
  --color-success-bg: #dcfce7;
  --color-warning: #d97706;
  --color-warning-bg: #fef3c7;
  --color-danger: #dc2626;
  --color-danger-bg: #fee2e2;
  --color-info: #0284c7;
  --color-info-bg: #e0f2fe;
  --color-neutral-bg: #f1f5f4;

  --text-primary: #1a2e29;
  --text-secondary: #5b6b67;
  --text-muted: #94a3a0;
  --border-color: #e2e8e6;

  --surface: #ffffff;
  --bg-body: #f6f8f7;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 40, 34, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 40, 34, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 40, 34, 0.14);

  --sidebar-width: 250px;
  --header-height: 64px;
  --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }

/* ---------------------------------------------------------------------------
   App shell layout
--------------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: #0f2b26;
  color: #cfe4e0;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
  transition: transform .25s ease;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand img { height: 34px; width: 34px; border-radius: 8px; object-fit: cover; background:#fff; }
.sidebar-brand .brand-text { font-weight: 700; font-size: 15px; color: #fff; line-height: 1.2; }
.sidebar-brand .brand-text small { display:block; font-weight:400; font-size: 11px; color:#8fb3ac; }

.sidebar-section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: #6f948d; padding: 16px 20px 6px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; font-size: 13.5px; color: #cfe4e0;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.05); }
.sidebar-nav a.active {
  background: rgba(132,204,22,.12); border-left-color: var(--color-accent); color: #fff; font-weight: 600;
}
.sidebar-nav a .icon { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }
.sidebar-nav .badge-count {
  margin-left: auto; background: var(--color-accent); color: #0f2b26; font-size: 11px;
  font-weight: 700; padding: 1px 7px; border-radius: 20px;
}

.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,43,38,.5); z-index: 190;
}

.main-wrap { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }

/* ---------------------------------------------------------------------------
   Topbar
--------------------------------------------------------------------------- */
.topbar {
  height: var(--header-height); background: var(--surface); border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 20px; position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-sm);
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.sidebar-toggle {
  display: none; background: none; border: none; font-size: 20px; color: var(--text-primary); padding: 6px;
}
.page-title { font-size: 17px; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-subtitle { font-size: 12px; color: var(--text-muted); }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  position: relative; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--color-neutral-bg); border: none; font-size: 16px; color: var(--text-secondary);
}
.icon-btn:hover { background: var(--color-primary-light); color: var(--color-primary); }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-danger);
  border: 2px solid var(--surface);
}
.user-menu { display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; border-radius: 30px; background: var(--color-neutral-bg); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
}
.user-name { font-size: 13px; font-weight: 600; line-height:1.1; }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

/* ---------------------------------------------------------------------------
   Content
--------------------------------------------------------------------------- */
.content { padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; flex: 1; }
.content-narrow { max-width: 760px; }

/* ---------------------------------------------------------------------------
   Cards / Panels
--------------------------------------------------------------------------- */
.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); border: 1px solid var(--border-color); min-width: 0; }
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-header h3 { font-size: 15px; font-weight: 700; }
.card-body { padding: 20px; }
.card + .card { margin-top: 18px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }

/* Fixed-column stat grids (used when a page needs an exact column count
   rather than auto-fit) — each collapses responsively on its own, so pages
   using these never need an inline grid-template-columns override (which
   would otherwise block the mobile breakpoint below from ever applying). */
.stat-grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stat-grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 992px) { .stat-grid-6, .stat-grid-5, .stat-grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 640px) { .stat-grid-6, .stat-grid-5, .stat-grid-4, .stat-grid-3, .stat-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat-card { background: var(--surface); border-radius: var(--radius-md); padding: 12px 14px; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); min-width: 0; overflow: hidden; border-left: 4px solid var(--border-color); }
.stat-value { overflow-wrap: break-word; }
.stat-card .stat-label { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing:.04em; margin-bottom: 3px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-card .stat-value { font-size: 21px; font-weight: 800; color: var(--text-primary); line-height: 1.15; }
.stat-card .stat-icon { float: right; font-size: 18px; opacity: .85; }
.stat-card.accent-green { background: #f0fdf4; border-left-color: var(--color-success); }
.stat-card.accent-green .stat-value { color: #15803d; }
.stat-card.accent-amber { background: #fffbeb; border-left-color: var(--color-warning); }
.stat-card.accent-amber .stat-value { color: #b45309; }
.stat-card.accent-red { background: #fef2f2; border-left-color: var(--color-danger); }
.stat-card.accent-red .stat-value { color: #b91c1c; }
.stat-card.accent-teal { background: #f0fdfa; border-left-color: var(--color-primary); }
.stat-card.accent-teal .stat-value { color: #0f766e; }

/* ---------------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content:center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-accent { background: var(--color-accent); color: #163008; }
.btn-accent:hover { background: var(--color-accent-dark); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border-color); color: var(--text-primary); }
.btn-outline:hover { background: var(--color-neutral-bg); }
.btn-danger { background: var(--color-danger-bg); color: #7f1d1d; }
.btn-danger:hover { background: var(--color-danger); color: #fff; }

/* Pill-shaped buttons (e.g. Edit / Deactivate row actions) */
.btn-pill { border-radius: 20px; }
.btn-indigo { background: #6366f1; color: #fff; }
.btn-indigo:hover { background: #4f46e5; }
.btn-pill-muted { background: #dbe3ea; color: #334155; }
.btn-pill-muted:hover { background: #cbd5e1; }
.btn-pill-green { background: #dcfce7; color: #166534; }
.btn-pill-green:hover { background: #bbf7d0; }

.btn-success { background: var(--color-success-bg); color: #14532d; }
.btn-success:hover { background: var(--color-success); color: #fff; }
.btn-warning { background: var(--color-warning-bg); color: #78350f; }
.btn-warning:hover { background: var(--color-warning); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon-only { padding: 8px; }

/* ---------------------------------------------------------------------------
   Forms
--------------------------------------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.form-label .required { color: var(--color-danger); }
.form-control, select.form-control, textarea.form-control {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  font-size: 13.5px; background: var(--surface); color: var(--text-primary); font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink:0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; cursor: pointer; inset: 0; background: #d1dbd9; border-radius: 24px; transition: .2s; }
.switch .slider:before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--color-primary); }
.switch input:checked + .slider:before { transform: translateX(18px); }

/* ---------------------------------------------------------------------------
   Tables (responsive: card-list on mobile)
--------------------------------------------------------------------------- */
.table-scroll { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
table.data-table th {
  text-align: left; padding: 11px 14px; background: var(--color-neutral-bg); color: var(--text-secondary);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; font-weight: 700; white-space: nowrap;
  position: sticky; top: 0;
}
/* Header alignment must match its column's data alignment, or numbers end
   up floating far from their own label (data right-aligned under a header
   that's still stuck on the left). table.data-table th above is more
   specific than the bare .text-right/.text-center utility classes, so
   these targeted overrides restore the intended alignment on headers. */
table.data-table th.text-right { text-align: right; }
table.data-table th.text-center { text-align: center; }
table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
table.data-table tbody tr:hover { background: #fafbfa; }
table.data-table tbody tr:last-child td { border-bottom: none; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---------------------------------------------------------------------------
   Badges
--------------------------------------------------------------------------- */
.badge { display: inline-flex; align-items:center; gap:4px; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.badge-success { background: var(--color-success-bg); color: #14532d; }
.badge-warning { background: var(--color-warning-bg); color: #78350f; }
.badge-danger { background: var(--color-danger-bg); color: #7f1d1d; }
.badge-info { background: var(--color-info-bg); color: #075985; }
.badge-neutral { background: var(--color-neutral-bg); color: var(--text-secondary); }
.badge-primary { background: var(--color-primary-light); color: var(--color-primary-dark); }

/* ---------------------------------------------------------------------------
   Pagination
--------------------------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; flex-wrap: wrap; border-top: 1px solid var(--border-color); }
.pagination-info { font-size: 12.5px; color: var(--text-muted); }
.pagination-controls { display: flex; gap: 4px; flex-wrap: wrap; }
.page-btn { padding: 6px 11px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 600; border: 1px solid var(--border-color); color: var(--text-primary); }
.page-btn:hover { background: var(--color-neutral-bg); }
.page-btn.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.page-btn.disabled { opacity: .4; pointer-events: none; }
.page-dots { padding: 6px 4px; color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   Alerts / Toasts
--------------------------------------------------------------------------- */
.alert { padding: 12px 16px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 14px; display:flex; gap:10px; align-items:flex-start; }
.alert-success { background: var(--color-success-bg); color: #14532d; }
.alert-danger { background: var(--color-danger-bg); color: #7f1d1d; }
.alert-warning { background: var(--color-warning-bg); color: #78350f; }
.alert-info { background: var(--color-info-bg); color: #075985; }

.toast-stack { position: fixed; top: 78px; right: 16px; z-index: 999; display:flex; flex-direction:column; gap:10px; max-width: 340px; }
.toast { background: var(--surface); border-left: 4px solid var(--color-primary); box-shadow: var(--shadow-lg); border-radius: var(--radius-md); padding: 12px 16px; font-size: 13px; animation: slideIn .25s ease; }
.toast.toast-danger { border-color: var(--color-danger); }
.toast.toast-success { border-color: var(--color-success); }
@keyframes slideIn { from { transform: translateX(30px); opacity:0;} to {transform:translateX(0); opacity:1;} }

/* ---------------------------------------------------------------------------
   Utility
--------------------------------------------------------------------------- */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mb-8{margin-bottom:8px;} .mb-12{margin-bottom:12px;} .mb-16{margin-bottom:16px;} .mb-20{margin-bottom:20px;}
.mt-8{margin-top:8px;} .mt-12{margin-top:12px;} .mt-16{margin-top:16px;}
.text-muted { color: var(--text-muted); } .text-sm { font-size: 12.5px; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.chip-tab { display:inline-flex; gap:6px; background: var(--color-neutral-bg); padding:4px; border-radius: 30px; }
.chip-tab a { padding: 7px 14px; border-radius: 20px; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.chip-tab a.active { background: var(--surface); color: var(--color-primary); box-shadow: var(--shadow-sm); }

/* Full-width underline tab bar (used where tabs should span the card,
   e.g. Users: All Users / Role Permissions) */
.tab-bar { display: flex; background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0; box-shadow: var(--shadow-sm); overflow: hidden; }
.tab-bar a {
  flex: 1; text-align: center; padding: 16px 12px; font-size: 14px; font-weight: 600;
  color: var(--text-muted); border-bottom: 3px solid var(--border-color); display: flex;
  align-items: center; justify-content: center; gap: 8px;
}
.tab-bar a:not(:last-child) { border-right: 1px solid var(--border-color); }
.tab-bar a.active { color: var(--color-primary); border-bottom-color: var(--color-primary); background: var(--surface); }
.tab-bar a .badge { font-size: 11px; }
@media (max-width: 640px) { .tab-bar a { padding: 12px 8px; font-size: 12.5px; gap: 4px; } }
@media (max-width: 420px) { .tab-bar a { padding: 10px 4px; font-size: 11px; flex-direction: column; gap: 2px; } }
.qr-box { text-align:center; padding: 18px; border: 1px dashed var(--border-color); border-radius: var(--radius-md); background: var(--color-neutral-bg); }
.qr-box img { margin: 0 auto 10px; width: 180px; height: 180px; background:#fff; padding:8px; border-radius: 8px; }
.url-copy { display:flex; gap:6px; align-items:center; background:#fff; border:1px solid var(--border-color); border-radius: var(--radius-sm); padding: 8px 10px; font-size:11.5px; word-break:break-all; }

/* ---------------------------------------------------------------------------
   Responsive breakpoints
--------------------------------------------------------------------------- */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay.open { display: block; }
  .main-wrap { margin-left: 0; }
  .sidebar-toggle { display: block; }
}

@media (max-width: 640px) {
  .content { padding: 14px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar-left { gap: 8px; }
  .topbar-right { gap: 4px; }
  .user-name, .user-role { display: none; }
  .page-title { font-size: 14px; }
  .page-subtitle { display: none; }
  .icon-btn { width: 32px; height: 32px; font-size: 14px; }
  .icon-btn[title="Help & Guide"] { display: none; }
  .user-menu { padding: 3px; gap: 0; background: none; }
  .user-avatar { width: 30px; height: 30px; }
  .card-body { padding: 14px; }
  .card-header { padding: 14px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card .stat-value { font-size: 20px; }

  /* Responsive table -> stacked cards */
  table.data-table.responsive-cards thead { display: none; }
  table.data-table.responsive-cards, table.data-table.responsive-cards tbody, table.data-table.responsive-cards tr, table.data-table.responsive-cards td { display: block; width: 100%; min-width: 0; }
  table.data-table.responsive-cards tr { margin-bottom: 12px; border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 8px 0; background:#fff; }
  table.data-table.responsive-cards td { border: none; padding: 6px 14px; display: flex; justify-content: space-between; gap: 10px; text-align: right; }
  table.data-table.responsive-cards td::before { content: attr(data-label); font-weight: 700; color: var(--text-secondary); text-align: left; font-size: 11.5px; text-transform: uppercase; flex-shrink: 0; }
  table.data-table.responsive-cards td input, table.data-table.responsive-cards td select { max-width: 140px; width: auto; flex: 1; min-width: 0; }

  table.data-table.responsive-cards td[data-label=""]::before { content: none; }
  table.data-table.responsive-cards td[data-label=""] { justify-content: flex-start; }

  /* Action cells often hold 2-4 buttons (View/Edit/Contam/Generate QR etc.)
     — side-by-side would overflow a phone width, so stack the label above
     and let the buttons wrap into a full-width row of their own. */
  table.data-table.responsive-cards td[data-label="Actions"] {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }
  table.data-table.responsive-cards td[data-label="Actions"] .flex {
    flex-wrap: wrap;
    justify-content: flex-start !important;
    margin-top: 6px;
  }
  table.data-table.responsive-cards td[data-label="Actions"] .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}