/* =====================================================================
   R-K PLASTIC ERP — Design System
   Palette: graphite chrome + resin-teal primary + amber warning accent
   Type: Sora (display) / Inter (body) / JetBrains Mono (figures)
   ===================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500&display=swap');

:root {
  /* --- Core palette --- */
  --ink:        #14181F;
  --graphite:   #1D222C;
  --graphite-2: #262C38;
  --teal:       #0EA394;
  --teal-dark:  #0B7F73;
  --amber:      #F2A93B;
  --red:        #E5484D;
  --green:      #1FA97C;
  --blue:       #3B82F6;

  --bg:         #F3F5F8;
  --surface:    #FFFFFF;
  --surface-2:  #F8F9FB;
  --border:     #E6E9EF;
  --text:       #171B21;
  --text-muted: #6B7280;
  --text-soft:  #9CA3AF;

  --radius-sm:  10px;
  --radius-md:  14px;
  --radius-lg:  20px;
  --radius-xl:  28px;

  --shadow-sm:  0 1px 2px rgba(20,24,31,.05), 0 1px 1px rgba(20,24,31,.04);
  --shadow-md:  0 8px 24px rgba(20,24,31,.08), 0 2px 6px rgba(20,24,31,.05);
  --shadow-lg:  0 20px 48px rgba(20,24,31,.14), 0 6px 16px rgba(20,24,31,.08);
  --shadow-glass: 0 8px 32px rgba(14,163,148,.10);

  --sidebar-w:  248px;
  --topbar-h:   68px;

  --font-display: 'Sora', 'Inter', sans-serif;
  --font-body:    'Inter', sans-serif;
  --font-mono:    'JetBrains Mono', monospace;

  --ease: cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
  --bg:         #0D1016;
  --surface:    #161A22;
  --surface-2:  #1B202A;
  --border:     #262C38;
  --text:       #EDEFF3;
  --text-muted: #9AA3B2;
  --text-soft:  #6B7383;
  --shadow-md:  0 8px 24px rgba(0,0,0,.35);
  --shadow-lg:  0 20px 48px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background .25s var(--ease), color .25s var(--ease);
}
h1, h2, h3, h4, .font-display { font-family: var(--font-display); letter-spacing: -0.01em; }
.mono { font-family: var(--font-mono); }
a { color: inherit; text-decoration: none; }
::selection { background: var(--teal); color: #fff; }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-soft); }

/* =====================================================================
   Layout shell
   ===================================================================== */

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

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--ink), var(--graphite));
  color: #DDE3EC;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform .25s var(--ease);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 22px 22px 18px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand .logo-mark {
  width: 38px; height: 38px; border-radius: 12px;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; color: #fff; font-size: 15px;
  box-shadow: 0 4px 14px rgba(14,163,148,.4);
}
.sidebar-brand .brand-text { font-family: var(--font-display); font-weight: 700; font-size: 15.5px; color: #fff; line-height: 1.2; }
.sidebar-brand .brand-sub { font-size: 11px; color: #8891A1; letter-spacing: .04em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-group { margin-bottom: 4px; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #6B7383; padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: #B7C0CE; font-size: 13.5px; font-weight: 500;
  margin-bottom: 2px; cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: linear-gradient(135deg, rgba(14,163,148,.22), rgba(14,163,148,.08));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(14,163,148,.35);
}
.nav-item.active svg { opacity: 1; color: var(--teal); }
.nav-badge {
  margin-left: auto; font-size: 10.5px; font-weight: 700;
  background: var(--amber); color: #2B1B03; padding: 1px 7px; border-radius: 20px;
}

.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.06); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); }
.user-chip:hover { background: rgba(255,255,255,.06); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover;
  background: var(--teal); color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; font-family: var(--font-display); flex-shrink: 0;
}
.user-chip .u-name { font-size: 13px; font-weight: 600; color: #fff; }
.user-chip .u-role { font-size: 11px; color: #8891A1; text-transform: capitalize; }

.main-wrap { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.menu-toggle { display: none; }
.search-box {
  flex: 1; max-width: 420px; position: relative;
}
.search-box input {
  width: 100%; padding: 9px 14px 9px 38px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 13.5px; color: var(--text); outline: none;
  transition: box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.search-box input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,163,148,.15); }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-soft); }
.search-kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 10.5px; color: var(--text-soft); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px;
}
.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer; position: relative; border: 1px solid transparent; background: none;
  transition: all .15s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
.dot-badge { position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--red); border: 2px solid var(--surface); }

.page { padding: 26px 28px 60px; max-width: 1440px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 22px; font-weight: 700; font-family: var(--font-display); }
.page-sub { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.breadcrumb { font-size: 12.5px; color: var(--text-soft); margin-bottom: 6px; }
.breadcrumb span { color: var(--text-muted); }

/* =====================================================================
   Buttons
   ===================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: transform .1s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease), border-color .15s var(--ease);
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(135deg, var(--teal), var(--teal-dark)); color: #fff; box-shadow: 0 6px 16px rgba(14,163,148,.28); }
.btn-primary:hover { box-shadow: 0 8px 22px rgba(14,163,148,.4); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--teal); color: var(--teal); }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-icon { width: 38px; height: 38px; padding: 0; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* =====================================================================
   Cards
   ===================================================================== */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.card-title { font-weight: 700; font-size: 15px; font-family: var(--font-display); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card .stat-icon {
  width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.teal  { background: rgba(14,163,148,.12); color: var(--teal); }
.stat-icon.amber { background: rgba(242,169,59,.15); color: var(--amber); }
.stat-icon.red   { background: rgba(229,72,77,.12); color: var(--red); }
.stat-icon.blue  { background: rgba(59,130,246,.12); color: var(--blue); }
.stat-icon.green { background: rgba(31,169,124,.12); color: var(--green); }
.stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; font-family: var(--font-display); margin-top: 4px; }
.stat-trend { font-size: 11.5px; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.stat-trend.up { color: var(--green); }
.stat-trend.down { color: var(--red); }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* =====================================================================
   Forms
   ===================================================================== */

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr !important; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field .req { color: var(--red); }
.field input, .field select, .field textarea {
  padding: 10px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); font-size: 13.5px; color: var(--text); font-family: var(--font-body);
  outline: none; transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,163,148,.14); background: var(--surface);
}
.field textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: 11.5px; color: var(--text-soft); }
.field-error { font-size: 11.5px; color: var(--red); }

/* =====================================================================
   Tables
   ===================================================================== */

.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead th {
  text-align: left; padding: 12px 16px; background: var(--surface-2); color: var(--text-muted);
  font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr { transition: background .12s var(--ease); }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 6px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
}
.badge.success { background: rgba(31,169,124,.12); color: var(--green); }
.badge.warning { background: rgba(242,169,59,.15); color: #92610C; }
.badge.danger  { background: rgba(229,72,77,.12); color: var(--red); }
.badge.neutral { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge.info    { background: rgba(59,130,246,.12); color: var(--blue); }

.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px 0; font-size: 12.5px; color: var(--text-muted); }
.pagination .pg-btns { display: flex; gap: 6px; }

/* =====================================================================
   Empty / loading states
   ===================================================================== */

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { width: 56px; height: 56px; color: var(--text-soft); margin-bottom: 14px; }
.empty-state h3 { font-size: 15px; margin: 0 0 6px; color: var(--text); }
.empty-state p { font-size: 13px; margin: 0 0 16px; }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: 8px; }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.page-loader {
  position: fixed; inset: 0; background: var(--bg); z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
}
.page-loader .ring { width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--teal); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.page-loader span { font-size: 13px; color: var(--text-muted); font-weight: 500; }

/* =====================================================================
   Toasts
   ===================================================================== */

.toast-stack { position: fixed; top: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: flex-start; gap: 10px; min-width: 300px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 13px 15px; box-shadow: var(--shadow-lg);
  animation: toast-in .28s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
.toast .t-icon { width: 20px; height: 20px; flex-shrink: 0; margin-top: 1px; }
.toast.success .t-icon { color: var(--green); }
.toast.error .t-icon { color: var(--red); }
.toast.info .t-icon { color: var(--blue); }
.toast .t-title { font-size: 13.5px; font-weight: 600; }
.toast .t-msg { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.toast .t-close { margin-left: auto; cursor: pointer; color: var(--text-soft); }

/* =====================================================================
   Modals
   ===================================================================== */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,12,16,.5); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 150; opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease);
}
.modal-overlay.show { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(.98); opacity: 0; transition: all .22s var(--ease);
}
.modal-overlay.show .modal { transform: translateY(0) scale(1); opacity: 1; }
.modal.modal-lg { max-width: 820px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-title { font-weight: 700; font-size: 16px; font-family: var(--font-display); }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }

/* =====================================================================
   Auth pages
   ===================================================================== */

.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #16332f 0%, var(--ink) 55%);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius-xl);
  padding: 40px 34px; box-shadow: var(--shadow-lg); position: relative;
}
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-logo .logo-mark { width: 54px; height: 54px; border-radius: 16px; background: linear-gradient(135deg, var(--teal), var(--teal-dark)); display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 800; color: #fff; font-size: 20px; box-shadow: 0 8px 20px rgba(14,163,148,.35); }
.auth-logo h1 { font-size: 18px; margin: 0; }
.auth-logo p { font-size: 12.5px; color: var(--text-muted); margin: 0; }
.auth-card .btn-primary { width: 100%; padding: 12px; }
.auth-links { display: flex; justify-content: space-between; font-size: 12.5px; margin-top: 4px; }
.auth-links a { color: var(--teal); font-weight: 600; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }

/* =====================================================================
   Chithi Bill print
   ===================================================================== */

.chithi-preview { background: #fff; color: #14181F; border: 1px dashed var(--border); border-radius: var(--radius-md); padding: 22px; font-family: 'Inter', sans-serif; }
.chithi-preview .ch-head { display: flex; justify-content: space-between; border-bottom: 2px solid var(--ink); padding-bottom: 10px; margin-bottom: 12px; }
.chithi-preview table { width: 100%; border-collapse: collapse; font-size: 13px; }
.chithi-preview th, .chithi-preview td { border-bottom: 1px solid #E6E9EF; padding: 7px 6px; text-align: left; }
.chithi-preview tfoot td { font-weight: 700; }

/* =====================================================================
   Utilities
   ===================================================================== */

.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; }
.mt-8{margin-top:8px}.mt-12{margin-top:12px}.mt-16{margin-top:16px}.mt-24{margin-top:24px}
.mb-8{margin-bottom:8px}.mb-12{margin-bottom:12px}.mb-16{margin-bottom:16px}
.text-muted { color: var(--text-muted); }
.text-soft { color: var(--text-soft); }
.text-right { text-align: right; }
.w-full { width: 100%; }
.hidden { display: none !important; }

@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .menu-toggle { display: flex; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-wrap { margin-left: 0 !important; }
  body { background: #fff; }
}
