/* =====================================================================
   SUTRA — Core stylesheet
   No framework dependency by design: keeps every page load tiny & fast.
   ===================================================================== */

:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-accent: #0ea5e9;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --color-bg: #f5f7fb;
  --color-surface: #ffffff;
  --color-border: #e5e9f0;
  --color-text: #1a2035;
  --color-text-muted: #64748b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --sidebar-width: 240px;
  --topbar-height: 60px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0 0 .75rem; }

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

.sidebar {
  width: var(--sidebar-width);
  background: #10182b;
  color: #cbd5e1;
  flex-shrink: 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  overflow-y: auto;
  z-index: 40;
  transition: transform .2s ease;
}
.sidebar-brand {
  padding: 18px 20px;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-brand .dot { color: var(--color-accent); }
.sidebar nav { padding: 8px 10px 24px; }
.sidebar .nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 14px 12px 6px; }
.sidebar a.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: #cbd5e1; font-size: 14px; font-weight: 500;
  margin-bottom: 2px;
}
.sidebar a.nav-link:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar a.nav-link.active { background: var(--color-primary); color: #fff; }
.sidebar .icon { width: 18px; text-align: center; opacity: .9; }

.main-col { margin-left: var(--sidebar-width); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; position: sticky; top: 0; z-index: 30;
}
.topbar .page-title { font-size: 17px; font-weight: 650; }
.topbar .user-chip { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--color-text-muted); }
.topbar .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}

.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--color-text); }

.content { padding: 24px; flex: 1; }

/* ---- Cards / surfaces ---- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-header h3 { margin: 0; font-size: 15px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.stat-card .label { font-size: 13px; color: var(--color-text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 24px; font-weight: 750; letter-spacing: -.02em; }
.stat-card .value.positive { color: var(--color-success); }
.stat-card .value.negative { color: var(--color-danger); }
.stat-card .sub { font-size: 12.5px; color: var(--color-text-muted); margin-top: 4px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; border: 1px solid transparent;
  cursor: pointer; transition: background .15s ease, border-color .15s ease;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-outline { background: #fff; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: #f8fafc; }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--color-danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---- Forms ---- */
label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 5px; color: #334155; }
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--color-border);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
  background: #fff; color: var(--color-text);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.help-text { font-size: 12.5px; color: var(--color-text-muted); margin-top: 4px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th {
  text-align: left; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--color-text-muted); padding: 10px 12px; border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
table.data-table td { padding: 12px; border-bottom: 1px solid #f0f2f6; vertical-align: middle; }
table.data-table tr:hover td { background: #fafbfd; }
table.data-table tr:last-child td { border-bottom: none; }

/* ---- Badges ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-muted { background: #eef1f6; color: #475569; }
.badge-info { background: #dbeafe; color: #1d4ed8; }

/* ---- Alerts / flash ---- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert ul { margin: 4px 0 0 18px; padding: 0; }

/* ---- Search box ---- */
.search-box { position: relative; max-width: 340px; }
.search-box input { padding-left: 34px; }
.search-box .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--color-text-muted); font-size: 14px; }
.autocomplete-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); max-height: 280px; overflow-y: auto; z-index: 50; display: none;
}
.autocomplete-results .result-item { padding: 10px 12px; cursor: pointer; font-size: 13.5px; border-bottom: 1px solid #f2f4f8; }
.autocomplete-results .result-item:hover { background: #f5f8ff; }
.autocomplete-results .result-item .sub { color: var(--color-text-muted); font-size: 12px; }

/* ---- Auth pages ---- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #0f172a, #1e3a8a); padding: 20px; }
.auth-card { background: #fff; width: 100%; max-width: 420px; border-radius: 16px; padding: 36px 32px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth-card .brand { text-align: center; font-size: 26px; font-weight: 800; color: var(--color-primary); margin-bottom: 4px; }
.auth-card .tagline { text-align: center; color: var(--color-text-muted); font-size: 13.5px; margin-bottom: 24px; }

/* ---- Invoice line item builder ---- */
.line-items-table th, .line-items-table td { padding: 8px; }
.line-items-table input, .line-items-table select { padding: 6px 8px; font-size: 13.5px; }
.totals-box { max-width: 340px; margin-left: auto; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.totals-box .row.grand { font-size: 18px; font-weight: 750; border-top: 1px solid var(--color-border); margin-top: 6px; padding-top: 10px; }

/* ---- Utility ---- */
.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-0 { margin-bottom: 0; }
.mt-3 { margin-top: 12px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--color-text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 10px; }

/* ---- Print (invoice PDF-friendly view) ---- */
.print-invoice { max-width: 800px; margin: 30px auto; background: #fff; padding: 40px; border-radius: 10px; box-shadow: var(--shadow-md); }
.print-toolbar { max-width: 800px; margin: 16px auto 0; display: flex; justify-content: flex-end; gap: 8px; }
@media print {
  .print-toolbar { display: none; }
  .print-invoice { box-shadow: none; margin: 0; max-width: 100%; }
  body { background: #fff; }
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-col { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .stat-grid { grid-template-columns: 1fr; }
  .auth-card { padding: 26px 20px; }
}
