/* === Global Reset === */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif; }

/* === THEME (Dark/Light) === */
:root {
  --bg: #0b1220; --card: #0f172a; --ring: #334155; --muted: #94a3b8;
  --text: #e2e8f0; --acc: #22c55e; --acc-2: #38bdf8; --chip: #111827;
  --shadow: 0 10px 30px rgba(2,6,23,.2);
  --primary: #3b82f6; --danger: #ef4444; --warning: #f59e0b; --ok: #16a34a;
}
[data-theme="light"] {
  --bg: #f8fafc; --card: #ffffff; --ring: #e5e7eb; --muted: #475569;
  --text: #0f172a; --acc: #16a34a; --acc-2: #0891b2; --chip: #f1f5f9;
}
html, body { background: var(--bg); color: var(--text); }

/* === TOPBAR === */
.topbar {
  position: sticky; top: 0; z-index: 999;
  min-height: 56px; display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 12px; padding: 10px 16px; background: rgba(15,23,42,.75); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--ring);
}
[data-theme="light"] .topbar { background: rgba(255,255,255,.8); }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-center { justify-self: stretch; }
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 800; letter-spacing: .2px; }
.brand-icon { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--acc), var(--acc-2)); color: #fff; box-shadow: var(--shadow); }
.icon-btn { border: 1px solid var(--ring); background: var(--card); color: var(--text); border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.icon-btn:hover { filter: brightness(1.05); }
.search { width: 100%; max-width: 640px; }
.search input { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--ring); outline: none; background: var(--card); color: var(--text); }
.profile { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--ring); background: var(--card); color: var(--text); border-radius: 999px; padding: 6px 10px; cursor: pointer; }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: linear-gradient(135deg, var(--acc), var(--acc-2)); color: #fff; display: inline-grid; place-items: center; font-weight: 800; }
.who { font-weight: 600; }
.caret { opacity: .7; }
.badge-wrap { position: relative; }
.badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 12px; display: inline-grid; place-items: center; box-shadow: var(--shadow); }

/* === SIDEBAR === */
.sidebar {
  position: fixed; top: 56px; left: 0; bottom: 0; width: 250px; padding: 14px;
  background: var(--card); border-right: 1px solid var(--ring);
  overflow-y: auto; transform: translateX(0); transition: transform .25s ease;
}
.sidebar .sidebar-head { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.sidebar a, .sidebar .side-toggle, .sidebar .side-sub a {
  display: block; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--text); border: 1px solid transparent;
}
.sidebar a:hover, .sidebar .side-toggle:hover { background: var(--chip); border-color: var(--ring); }
.sidebar a.active { background: linear-gradient(135deg, var(--acc), var(--acc-2)); color: #fff; }
.sidebar .side-toggle { width: 100%; text-align: left; background: transparent; cursor: pointer; margin-top: 8px; }
.sidebar .side-toggle.open { background: var(--chip); border-color: var(--ring); }
.sidebar .side-sub { display: none; margin-top: 6px; padding-left: 4px; }
.sidebar .side-sub.open { display: block; }
.sidebar-foot { position: absolute; bottom: 10px; left: 14px; right: 14px; display: grid; gap: 8px; }
/* Ensure Users submenu opens when the toggle is open */
.sidebar .side-sub { 
  display: none; 
  max-height: 0; 
  overflow: hidden; 
  transition: max-height .25s ease;
}
.sidebar .side-toggle.open + .side-sub { 
  display: block !important; 
  max-height: 500px; 
}

/* (Optional) visually indicate open state */
.sidebar .side-toggle.open { background: var(--chip); border-color: var(--ring); }

/* === LAYOUT === */
.main-content { margin-left: 270px; padding: 20px; transition: margin-left .25s ease; }
.wrap { padding: 24px; }
.grid { display: grid; gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.widgets { display: grid; gap: 16px; grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 1200px){ .widgets{ grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px){ .widgets{ grid-template-columns: 1fr; } }
.card { background: var(--card); color: var(--text); border: 1px solid var(--ring); border-radius: 14px; box-shadow: 0 10px 30px rgba(2,6,23,.05); }
.card .p { padding: 16px; }
.section-title { padding: 16px 16px 6px 16px; font-weight: 700; color: var(--text); }


/* Sidebar behavior on mobile */
body.sidebar-open .sidebar { transform: translateX(0); }
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-110%); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main-content, .site-footer { margin-left: 0; }
}

/* === DROPDOWNS === */
.dropdown { position: relative; }
.dropdown .dropdown-menu {
  position: absolute; top: calc(100% + 8px); left: 0; min-width: 260px;
  background: var(--card); border: 1px solid var(--ring); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: none; z-index: 1000;
}
.dropdown .dropdown-menu.right { right: 0; left: auto; }
.dropdown .dropdown-menu.open { display: block; }
.dropdown-title { font-size: 12px; color: var(--muted); padding: 6px 8px 8px 8px; text-transform: uppercase; letter-spacing: .08em; }
.dropdown-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px; border-radius: 10px; color: var(--text); text-decoration: none; }
.dropdown-item:hover { background: var(--chip); }
.dropdown-empty { padding: 12px; color: var(--muted); text-align: center; }
.chip { background: var(--chip); border: 1px solid var(--ring); padding: 2px 8px; border-radius: 999px; font-size: 12px; }

/* === FOOTER === */
.site-footer {
  margin-left: 270px; padding: 14px 20px; border-top: 1px solid var(--ring);
  background: var(--card); display: flex; justify-content: space-between; align-items: center;
}
.site-footer .footer-links a { color: var(--muted); text-decoration: none; margin-left: 12px; }
.site-footer .footer-links a:hover { color: var(--text); }
@media (max-width: 1024px) { .site-footer { margin-left: 0; } }

/* === TOASTS === */
.toast-stack { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 2000; }
.toast {
  background: var(--card); color: var(--text); border: 1px solid var(--ring); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow); transform: translateY(10px); opacity: 0; transition: .25s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* === TABLES === */
.table-container { margin-top: 20px; overflow-x: auto; }
.admin-table {
  width: 100%; border-collapse: collapse; background: var(--card); color: var(--text);
  border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,0.05); border: 1px solid var(--ring);
}
.admin-table th, .admin-table td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--ring); font-size: 0.95rem; }
.admin-table th { background-color: rgba(148,163,184,.12); color: var(--text); }
.admin-table tr:hover { background-color: rgba(148,163,184,.08); }

/* Scrollable wide tables + no-wrap on phones */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.responsive-table { width: 100%; border-collapse: collapse; }
@media (max-width: 640px) {
  .responsive-table th, .responsive-table td { white-space: nowrap; }
}

/* === KPI labels in cards === */
.kpi-title{font-size:12px;color:var(--muted);text-transform:uppercase;letter-spacing:.08em}
.kpi-val{font-size:28px;font-weight:800;margin-top:6px}

/* === ORDER TABS & CARDS === */
.order-tabs { margin-top: 10px; display: flex; gap: 10px; flex-wrap: wrap; }
.tab-btn {
  padding: 8px 16px; border: 1px solid var(--ring); background: var(--chip);
  border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--text);
}
.tab-btn.active { background: linear-gradient(135deg, var(--acc), var(--acc-2)); color: #fff; border-color: transparent; }
.order-card {
  background: var(--card); color: var(--text);
  border-radius: 12px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  border: 1px solid var(--ring); margin-bottom: 20px;
}
.order-status { padding: 4px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; }
.status-pending { background: #ffe082; color: #1f2937; }
.status-assigned { background: #4fc3f7; color: #0b1020; }
.status-accepted { background: #81c784; color: #0b1020; }
.status-delivered { background: #9e9e9e; color: #0b1020; }

/* === STATUS BADGES (tables) === */
.status{padding:4px 8px;border-radius:999px;font-weight:700;font-size:12px;display:inline-block}
.s-pending{background:#fff7ed;color:#c2410c;border:1px solid #fed7aa}
.s-inprogress{background:#ecfeff;color:#0e7490;border:1px solid #a5f3fc}
.s-delivered{background:#ecfdf5;color:#047857;border:1px solid #a7f3d0}
.s-cancelled{background:#fef2f2;color:#991b1b;border:1px solid #fecaca}
.danger{color:#dc2626;font-weight:700}
.warn{color:#b45309;font-weight:700}
.ok{color:#16a34a;font-weight:700}

/* === BUTTONS === */
.btn { display:inline-block; text-decoration:none; border:none; border-radius:10px; font-weight:600; cursor:pointer; transition:filter .2s ease, background-color .2s ease; }
.btn:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--primary); color:#fff; padding: 8px 14px; font-size: .9rem; border-radius: 8px; }
.btn-approve  { background: var(--acc); color:#fff; padding: 8px 14px; border-radius: 8px; }
.btn-reject   { background: var(--danger); color:#fff; padding: 8px 14px; border-radius: 8px; }
.btn-small    { background: var(--acc); color:#fff; padding: 6px 12px; font-size: 13px; border-radius: 8px; }

/* Quick Actions */
.action-buttons { display:flex; flex-wrap:wrap; gap:12px; }
.btn-action {
  display:inline-block; padding:10px 12px; border-radius:10px; text-decoration:none; font-weight:600;
  background: linear-gradient(135deg, var(--acc), var(--acc-2)); color:#fff; border:1px solid transparent; text-align:center;
}
.btn-action:hover { filter: brightness(1.05); }
@media (max-width: 1024px) { .btn-action { flex: 1 1 calc(50% - 12px); } }
@media (max-width: 640px)  { .btn-action { flex: 1 1 100%; } }

/* === FORMS === */
.approval-page { padding: 20px; }
.approval-columns { display: flex; gap: 2rem; flex-wrap: wrap; }
.approval-column {
  flex: 1; min-width: 300px; background: var(--card); color: var(--text);
  padding: 1.5rem; border-radius: 12px; box-shadow: 0 0 10px rgba(0,0,0,0.06); border: 1px solid var(--ring);
}
.user-card form label { display: block; margin-top: 10px; margin-bottom: 4px; font-weight: 500; }
.user-card form input, .user-card form select, .user-card form textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--ring); border-radius: 6px; font-size: 0.95rem; margin-bottom: 10px;
  background-color: var(--card); color: var(--text);
}
.user-card .form-row { display: flex; gap: 1rem; }
.user-card .form-row > div { flex: 1; }

/* === LOGIN === */
.login-body { background-color: var(--bg); display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; }
.login-wrapper { width: 100%; max-width: 400px; padding: 20px; }
.login-card { background: var(--card); border-radius: 10px; padding: 30px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); border: 1px solid var(--ring); }
.login-title { font-size: 1.5rem; font-weight: bold; margin-bottom: 25px; text-align: center; }
.login-form .form-group { margin-bottom: 20px; display: flex; flex-direction: column; }
.login-form label { font-weight: 500; margin-bottom: 5px; color: var(--text); }
.login-form input { padding: 10px; border: 1px solid var(--ring); border-radius: 6px; font-size: 14px; transition: border 0.3s; background: var(--card); color: var(--text); }
.login-form input:focus { border-color: var(--acc-2); outline: none; }
.btn-primary { width: 100%; background-color: #4f46e5; color: #fff; padding: 12px; font-size: 16px; font-weight: 600; border: none; border-radius: 6px; cursor: pointer; transition: background-color 0.3s; }
.btn-primary:hover { background-color: #4338ca; }

/* === MODAL (generic) === */
#modal-area { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,.45); z-index: 3000; }
#modal-area.open { display: flex; }
#modal-area .modal-card { background: var(--card); border: 1px solid var(--ring); border-radius: 12px; max-width: 860px; width: 96%; max-height: 88vh; overflow: auto; }

/* === CANVAS sizing in cards === */
.card canvas { width: 100% !important; max-width: 100%; }

/* === RESPONSIVE TWEAKS === */
@media (max-width: 640px) {
  .card .p { padding: 12px; }
  #statusChart, #revChart { height: 120px !important; }
}

/* === PRINT (hide chrome on invoices/challans) === */
@media print {
  .topbar, .sidebar, .site-footer, #toast-stack { display: none !important; }
  .main-content { margin: 0 !important; padding: 0 !important; }
  body { background: #fff; color: #000; }
}
/* Ensure topbar columns are balanced across devices */
.topbar { grid-template-columns: auto 1fr auto; }

/* Sidebar spacing & submenu visibility */
.sidebar-group { margin-top: 8px; }
.sidebar .side-sub { display: none; margin-top: 6px; padding-left: 4px; }
.sidebar .side-sub.open { display: block !important; } /* force-open when toggled */

/* Prevent wrapping of submenu links on small screens */
.sidebar .side-sub a { white-space: nowrap; }

/* Make the 3-widget row comfy on phones */
@media (max-width: 640px) {
  #statusChart, #revChart { height: 120px !important; }
  .card .p { padding: 12px; }
}

/* Keep tables usable on narrow widths */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.responsive-table th, .responsive-table td { white-space: nowrap; }

/* Quick actions flow nicely at tablet & below */
@media (max-width: 1024px) {
  .btn-action { flex: 1 1 calc(50% - 10px); text-align: center; }
}
@media (max-width: 640px) {
  .btn-action { flex: 1 1 100%; }
}

