/* ==========================================================================
   Mortacc App Shell — Design System & Base Styles
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w:    232px;
    --topbar-h:     58px;
    --radius:       8px;
    --radius-lg:    12px;

    /* Brand */
    --brand:        #2563eb;
    --brand-dark:   #1d4ed8;
    --brand-soft:   #eff6ff;
    --brand-muted:  #bfdbfe;

    /* Sidebar */
    --sb-bg:        #0f172a;
    --sb-border:    rgba(255,255,255,.07);
    --sb-text:      rgba(255,255,255,.55);
    --sb-text-hover:#fff;
    --sb-active-bg: rgba(37,99,235,.18);
    --sb-active:    #93c5fd;
    --sb-label:     rgba(255,255,255,.25);
    --sb-icon:      rgba(255,255,255,.45);

    /* Surface */
    --bg:           #f8fafc;
    --surface:      #ffffff;
    --surface-2:    #f1f5f9;
    --border:       #e2e8f0;
    --border-soft:  #f1f5f9;

    /* Text */
    --ink:          #0f172a;
    --ink-2:        #334155;
    --ink-3:        #64748b;
    --ink-4:        #94a3b8;

    /* Semantic */
    --green:        #16a34a;
    --green-bg:     #dcfce7;
    --amber:        #d97706;
    --amber-bg:     #fef3c7;
    --red:          #dc2626;
    --red-bg:       #fee2e2;
    --purple:       #7c3aed;
    --purple-bg:    #ede9fe;
    --teal:         #0d9488;
    --teal-bg:      #ccfbf1;

    --shadow-xs:    0 1px 2px rgba(15,23,42,.05);
    --shadow-sm:    0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
    --shadow:       0 4px 6px rgba(15,23,42,.05), 0 2px 4px rgba(15,23,42,.04);
    --shadow-md:    0 10px 15px rgba(15,23,42,.06), 0 4px 6px rgba(15,23,42,.04);
    --shadow-lg:    0 20px 25px rgba(15,23,42,.08), 0 8px 10px rgba(15,23,42,.04);
    --transition:   140ms cubic-bezier(.4,0,.2,1);
}

html, body { height: 100%; }

body {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── App shell ─────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sb-bg);
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-logo {
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--sb-border);
    flex-shrink: 0;
}

.sidebar-logo .wordmark {
    font-family: 'DM Serif Display', serif;
    font-size: 21px;
    color: #fff;
    letter-spacing: -.3px;
    text-decoration: none;
    display: block;
}

.sidebar-logo .wordmark span { color: #60a5fa; }

.sidebar-logo .tagline {
    font-size: 10.5px;
    color: var(--sb-label);
    margin-top: 2px;
    letter-spacing: .6px;
    text-transform: uppercase;
    font-weight: 500;
}

.sidebar-firm {
    padding: 12px 18px;
    border-bottom: 1px solid var(--sb-border);
    flex-shrink: 0;
}

.sidebar-firm .firm-name {
    font-size: 12.5px;
    font-weight: 600;
    color: rgba(255,255,255,.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-firm .firm-code {
    font-size: 11px;
    color: var(--sb-label);
    margin-top: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 10px 10px;
    overflow-y: auto;
}

.nav-section { margin-bottom: 4px; }

.nav-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .9px;
    text-transform: uppercase;
    color: var(--sb-label);
    padding: 14px 8px 5px;
    display: block;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: 7px;
    color: var(--sb-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 400;
    transition: all var(--transition);
    cursor: pointer;
    margin-bottom: 1px;
    white-space: nowrap;
    position: relative;
}

.nav-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: .65;
}

.nav-item:hover {
    background: rgba(255,255,255,.07);
    color: var(--sb-text-hover);
}

.nav-item:hover svg { opacity: 1; }

.nav-item.active {
    background: var(--sb-active-bg);
    color: var(--sb-active);
    font-weight: 500;
}

.nav-item.active svg { opacity: 1; }

.nav-badge {
    margin-left: auto;
    background: rgba(239,68,68,.25);
    color: #fca5a5;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 99px;
}

.nav-badge.blue {
    background: rgba(37,99,235,.25);
    color: #93c5fd;
}

.sidebar-footer {
    padding: 10px;
    border-top: 1px solid var(--sb-border);
    flex-shrink: 0;
}

/* ── Main area ─────────────────────────────────────────── */
.main-area {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}
.main-area--full { margin-left: 0; }

/* ── Topbar ────────────────────────────────────────────── */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }

.topbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--ink-3);
}

.topbar-breadcrumb .crumb-sep { color: var(--ink-4); }

.topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand-soft);
    border: 1.5px solid var(--brand-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--brand);
    cursor: pointer;
}

/* ── Content ───────────────────────────────────────────── */
.content {
    padding: 24px 28px;
    flex: 1;
}

/* ── Page header ───────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-header-text h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -.3px;
}

.page-header-text p {
    font-size: 13.5px;
    color: var(--ink-3);
    margin-top: 3px;
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-sm); }

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.card-subtitle {
    font-size: 12.5px;
    color: var(--ink-3);
    margin-top: 1px;
}

.card-body { padding: 20px; }

/* ── Stat cards ────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-xs);
    transition: all var(--transition);
    position: relative; overflow: hidden;
}

.stat-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }

.stat-label {
    font-size: 11.5px;
    font-weight: 500;
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 26px;
    font-weight: 600;
    color: var(--ink);
    line-height: 1;
    letter-spacing: -.5px;
}

.stat-sub {
    font-size: 11.5px;
    color: var(--ink-4);
    margin-top: 5px;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

.btn-primary   { background: var(--brand);    color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success   { background: var(--green);   color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-warning   { background: var(--amber);   color: #fff; }
.btn-warning:hover { background: #b45309; }
.btn-danger    { background: var(--red);     color: #fff; }
.btn-danger:hover  { background: #b91c1c; }
.btn-purple    { background: var(--purple);  color: #fff; }
.btn-purple:hover  { background: #6d28d9; }
.btn-teal      { background: var(--teal);    color: #fff; }
.btn-teal:hover    { background: #0f766e; }
.btn-dark      { background: var(--ink-2);   color: #fff; }
.btn-dark:hover    { background: var(--ink); }
.btn-ghost     { background: transparent; color: var(--ink-2); border: 1px solid var(--border); }
.btn-ghost:hover   { background: var(--surface-2); border-color: #cbd5e1; }
.btn-sm  { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-lg  { padding: 10px 22px; font-size: 14.5px; }
.btn-icon { padding: 7px; border-radius: var(--radius); }

/* ── Status badges ─────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 500;
}

.badge::before {
    content: '';
    display: block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-not-started { background: var(--surface-2);  color: var(--ink-3); }
.badge-in-progress { background: var(--amber-bg);   color: var(--amber); }
.badge-in-review   { background: var(--purple-bg);  color: var(--purple); }
.badge-completed   { background: var(--green-bg);   color: var(--green); }
.badge-needs-attention { background: var(--red-bg); color: var(--red); }

/* ── Table ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--ink-3);
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: var(--surface);
}

tbody tr {
    border-bottom: 1px solid var(--border-soft);
    transition: background var(--transition);
}

tbody tr:hover { background: #f8fafc; }
tbody tr:last-child { border-bottom: none; }

tbody td {
    padding: 12px 14px;
    vertical-align: middle;
    font-size: 13.5px;
    color: var(--ink-2);
}

/* ── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ink-2);
    margin-bottom: 5px;
}

.form-hint {
    font-size: 11.5px;
    color: var(--ink-4);
    margin-top: 4px;
}

.form-control {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 13.5px;
    color: var(--ink);
    background: var(--surface);
    transition: var(--transition);
    outline: none;
    line-height: 1.5;
}

.form-control:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

textarea.form-control { min-height: 96px; resize: vertical; }
select.form-control   { cursor: pointer; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-full   { grid-column: 1 / -1; }

/* ── Alerts ────────────────────────────────────────────── */
.alert {
    padding: 11px 14px;
    border-radius: var(--radius);
    font-size: 13.5px;
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin-bottom: 18px;
}

.alert-success { background: var(--green-bg);  color: #15803d; border: 1px solid #bbf7d0; }
.alert-warning { background: var(--amber-bg);  color: #92400e; border: 1px solid #fde68a; }
.alert-danger  { background: var(--red-bg);    color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: var(--brand-soft);color: #1e40af; border: 1px solid var(--brand-muted); }

/* ── Dividers & helpers ────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.text-muted   { color: var(--ink-3); }
.text-small   { font-size: 12px; }
.text-strong  { font-weight: 600; }
.gap-row      { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.mt-4 { margin-top: 28px; }
.mb-1 { margin-bottom: 6px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 20px; }
.mb-4 { margin-bottom: 28px; }
.inline-form { display: inline; }

/* ── Tabs ──────────────────────────────────────────────── */
.tab-nav {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.tab-link {
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-3);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: var(--transition);
    white-space: nowrap;
}

.tab-link:hover { color: var(--ink); }
.tab-link.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 52px 20px;
    color: var(--ink-3);
}

.empty-state svg {
    width: 44px;
    height: 44px;
    margin: 0 auto 14px;
    display: block;
    opacity: .3;
}

.empty-state p { font-size: 13.5px; }

/* ── Toast ─────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 22px;
    right: 22px;
    background: var(--ink);
    color: #fff;
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    display: none;
    z-index: 999;
    box-shadow: var(--shadow-md);
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 1200px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 960px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
    .sidebar.open { transform: none; }
    .main-area { margin-left: 0; }
    .content { padding: 16px; }
    .topbar { padding: 0 16px; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .form-grid-2 { grid-template-columns: 1fr; }
}

/* Dark Mode */
[data-theme=dark] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --border: #334155;
    --border-soft: #1e293b;
    --ink: #f1f5f9;
    --ink-2: #cbd5e1;
    --ink-3: #94a3b8;
    --ink-4: #64748b;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.3);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
    --shadow-md: 0 10px 15px rgba(0,0,0,.4);
}
[data-theme=dark] .topbar { background: var(--surface); border-bottom-color: var(--border); }
[data-theme=dark] table thead th { background: var(--surface); color: var(--ink-3); }
[data-theme=dark] tbody tr:hover { background: rgba(255,255,255,.03); }
[data-theme=dark] .form-control { background: var(--surface); color: var(--ink); border-color: var(--border); }
[data-theme=dark] .card { background: var(--surface); border-color: var(--border); }
[data-theme=dark] .stat-card { background: var(--surface); border-color: var(--border); }
[data-theme=dark] .btn-ghost { color: var(--ink-2); border-color: var(--border); }
[data-theme=dark] .btn-ghost:hover { background: var(--surface-2); }
[data-theme=dark] .badge-not-started { background: var(--surface-2); }
[data-theme=dark] .badge-completed { background: rgba(22,163,74,.2); color: #4ade80; }
[data-theme=dark] .alert-info { background: rgba(37,99,235,.15); color: #93c5fd; border-color: rgba(37,99,235,.2); }
[data-theme=dark] .empty-state { color: var(--ink-4); }
[data-theme=dark] .tab-nav { border-bottom-color: var(--border); }

.theme-toggle-btn {
    width: 32px; height: 32px; border-radius: 50%;
    border: 1.5px solid var(--border); background: var(--surface);
    cursor: pointer; font-size: 15px; display: flex; align-items: center;
    justify-content: center; transition: all var(--transition);
    padding: 0; line-height: 1; font-family: inherit;
}
.theme-toggle-btn:hover { border-color: var(--brand); }

/* ==========================================================================
   Mobile Responsive — breakpoints at 768px (tablet) and 480px (phone)
   ========================================================================== */

@media (max-width: 768px) {
  /* Sidebar → hidden by default, toggle with hamburger */
  .sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 100;
    transition: left 0.25s ease; box-shadow: var(--shadow-md); }
  .sidebar.open { left: 0; }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99; }
  .sidebar.open ~ .sidebar-overlay { display: block; }

  /* Main content full-width */
  .main { margin-left: 0 !important; }
  .topbar { left: 0 !important; padding: 0 1rem; }
  .topbar .hamburger { display: inline-flex !important; }

  /* Tables — horizontal scroll */
  table { display: block; overflow-x: auto; white-space: nowrap; }

  /* Cards and grids */
  .overview-grid, .dashboard-grid, .pricing-grid, .security-grid {
    grid-template-columns: 1fr !important;
  }

  /* Forms */
  .form-row { flex-direction: column; gap: 0.5rem; }
  .form-row > * { width: 100% !important; }

  /* Modals */
  .modal-content { width: 95vw; max-width: 95vw; margin: 2rem auto; }

  /* Buttons — full-width on mobile */
  .btn-group { flex-direction: column; }
  .btn-group .btn { width: 100%; }

  /* Top bar actions — hide labels, show icons */
  .topbar-actions .btn span { display: none; }

  /* Tabs — scroll */
  .tab-nav { overflow-x: auto; flex-wrap: nowrap; }

  /* Plan cards */
  .plan { margin-bottom: var(--gap); }
}

@media (max-width: 480px) {
  :root { --gap: 0.75rem; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  .topbar-title { font-size: 0.95rem; }
  .stat-card { padding: 1rem; }
  .stat-card .stat-value { font-size: 1.5rem; }
  .card { padding: 1rem; }

  /* Client portal — full-width cards */
  .portal-grid { grid-template-columns: 1fr !important; }

  /* Document viewer — fit screen */
  .document-preview { max-width: 100%; height: auto; }

  /* Hide non-essential columns in tables */
  .hide-mobile { display: none; }

  /* Login/signup forms */
  .auth-card { width: 95vw; margin: 1rem auto; padding: 1.5rem; }
  .auth-card h1 { font-size: 1.3rem; }

  /* Smaller fonts */
  body { font-size: 14px; }
  .ov-stat { font-size: 1.5rem !important; }
  .plan-price { font-size: 2rem !important; }
}

/* Hamburger menu icon (hidden on desktop) */
.hamburger {
  display: none !important;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  border: none; background: none; cursor: pointer;
  font-size: 1.5rem; color: var(--ink);
  margin-right: 0.5rem;
}

/* Sidebar overlay (mobile only) */
.sidebar-overlay { display: none; }

/* Touch-friendly: larger tap targets on mobile */
@media (pointer: coarse) {
  .btn, .nav-item a, .tab, .form-control {
    min-height: 44px;
  }
  .btn-sm { min-height: 36px; }
  input[type="checkbox"], input[type="radio"] {
    width: 22px; height: 22px;
  }
}
