/* ============================================================
   Merkora — Shared Design System
   ============================================================ */

/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:      #2563eb;
    --blue-dark: #1d4ed8;
    --blue-light:#dbeafe;
    --blue-pale: #eff6ff;
    /* Brand primary (emerald) — kept in sync with style.css so primary buttons
       look identical on shell pages (merkora.css only) and content pages
       (style.css), regardless of stylesheet load order. */
    --primary:       #10b981;
    --primary-hover: #059669;
    --green:     #16a34a;
    --amber:     #d97706;
    --red:       #dc2626;
    --red-pale:  #fef2f2;
    --text:      #1e293b;
    --text-muted:#64748b;
    --border:    #e2e8f0;
    --bg:        #f1f5f9;
    --white:     #ffffff;
    --sidebar-w: 220px;
    --topbar-h:  52px;
    --radius:    8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,.10);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
    padding-top: var(--topbar-h);
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
    box-shadow: 0 2px 6px rgba(0,0,0,.15);
}

.topbar-left  { display: flex; align-items: center; gap: .75rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }

.sidebar-toggle {
    background: none; border: none; color: #bfdbfe;
    font-size: 1.1rem; cursor: pointer; padding: .25rem .35rem;
    border-radius: 4px; line-height: 1;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.15); color: #fff; }

.topbar-logo { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: -.3px; }
.topbar-logo:hover { text-decoration: none; opacity: .9; }

.topbar-module { color: #93c5fd; font-size: .85rem; }

.tenant-badge {
    display: flex; align-items: center; gap: .35rem;
    background: rgba(255,255,255,.12);
    border-radius: 20px;
    padding: .2rem .65rem;
    font-size: .8rem; color: #bfdbfe;
}

.topbar-user { display: flex; align-items: center; gap: .3rem; font-size: .85rem; color: #bfdbfe; }
.logout-form { display: inline; }
.btn-link {
    background: none; border: none; color: #93c5fd;
    cursor: pointer; font-size: .8rem; padding: .15rem .35rem;
    border-radius: 4px;
}
.btn-link:hover { color: #fff; background: rgba(255,255,255,.12); }
.topbar-signout { font-size: .8rem; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: var(--topbar-h); left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--white);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    transition: transform .2s ease;
    z-index: 900;
}

body.sidebar-collapsed .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
body.sidebar-collapsed .page-content { margin-left: 0; }

.sidebar-nav { list-style: none; padding: .75rem 0; }
.sidebar-nav li { margin: .15rem .5rem; }

.sidebar-link {
    display: flex; align-items: center; gap: .6rem;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: .875rem;
    transition: background .12s, color .12s;
}
.sidebar-link:hover { background: var(--blue-pale); color: var(--blue); text-decoration: none; }
.sidebar-link.active { background: var(--blue-pale); color: var(--blue); font-weight: 600; }

.sidebar-section {
    padding: .5rem 1.25rem .25rem;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: .5rem;
}

.nav-icon { font-size: .95rem; width: 1.2rem; text-align: center; }

/* ── Page content area ─────────────────────────────────────── */
.page-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;            /* allow flex item to shrink so wide content scrolls inside, not the page */
    padding: 1.5rem;
    transition: margin-left .2s ease;
}

/* ── Page header ───────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.page-title { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.page-subtitle { font-size: .85rem; color: var(--text-muted); margin-top: .2rem; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.card-header {
    padding: .9rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-weight: 600; font-size: .95rem; }
.card-body { padding: 1.25rem; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .45rem 1rem;
    border-radius: 6px;
    font-size: .85rem; font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .12s, border-color .12s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: #94a3b8; background: var(--bg); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-xs { padding: .2rem .55rem; font-size: .75rem; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
    display: block;
    font-size: .8rem; font-weight: 600;
    color: #475569; margin-bottom: .35rem;
}
.form-control {
    width: 100%;
    padding: .55rem .85rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .875rem;
    background: #fff;
    outline: none;
    transition: border-color .15s;
}
.form-control:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-check { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.form-check input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--blue); }
.form-check-label { font-size: .875rem; color: var(--text); cursor: pointer; }

/* ── Tables ────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
    text-align: left;
    padding: .65rem 1rem;
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    font-weight: 600; font-size: .8rem;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .04em;
}
.table td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8fafc; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: .2rem .5rem;
    border-radius: 20px;
    font-size: .72rem; font-weight: 600;
    white-space: nowrap;
}
.badge-blue   { background: var(--blue-light); color: var(--blue-dark); }
.badge-green  { background: #dcfce7; color: var(--green); }
.badge-amber  { background: #fef3c7; color: var(--amber); }
.badge-red    { background: var(--red-pale); color: var(--red); }
.badge-grey   { background: #f1f5f9; color: var(--text-muted); }

/* Locked fiscal-year badge (shared by Books receipts / bank / invoices) */
.badge-lock{display:inline-flex;align-items:center;gap:4px;padding:2px 10px;border-radius:99px;font-size:.75rem;font-weight:600;background:#fef3c7;color:#92400e;}

/* ── shared status pills — one semantic palette across modules ── */
.mkpill{display:inline-flex;align-items:center;gap:6px;padding:2px 10px;border-radius:99px;font-size:.72rem;font-weight:700;white-space:nowrap;}
.mkpill.grey{background:#f1f5f9;color:#475569;}      /* draft / inactive / archived */
.mkpill.amber{background:#fff3da;color:#9a6a12;}     /* pending / submitted / waiting */
.mkpill.green{background:#dcfce7;color:#15803d;}     /* active / approved / paid */
.mkpill.blue{background:#dbeafe;color:#1d4ed8;}      /* info / in-progress */
.mkpill.violet{background:#ede9fe;color:#6d28d9;}    /* done / reimbursed / issued */
.mkpill.red{background:#fee2e2;color:#b91c1c;}       /* rejected / breached / danger */

/* ── breadcrumb (flow-v2 look, shared) ─────────────────────── */
/* MER-221: every sub-page carries its breadcrumbs with a line BELOW them. The line takes the
   customer's highlight colour when the page belongs to a customer (set --cc-color on the
   .crumb), and a quiet neutral otherwise. Overview pages - the ones a menu entry opens -
   have no breadcrumbs and so no line. */
.crumb{font-size:13px;color:#8a93a0;font-weight:600;display:flex;align-items:center;gap:7px;
       margin-bottom:16px;padding-bottom:9px;border-bottom:3px solid var(--cc-color,#e4e8ee);}
.crumb a{color:inherit;} .crumb a:hover{color:#1f57c4;} .crumb .sep{color:#e4e8ee;} .crumb b{color:#1e2530;}
/* inside the older flex .page-title header the crumb takes a row of its own, line and all */
.page-title > .crumb{flex:0 0 100%;margin-bottom:4px;}

/* ── MER-218: the page grid ────────────────────────────────── */
/* Four equal columns, modelled on the Flow overview (four KPI tiles, 16px gaps). Every widget
   on a page is 1, 2, 3 or 4 columns wide - nothing in between, nothing hand-sized. Narrower
   screens collapse to two columns, then one; spans clamp to what is available.
   Prefixed on purpose: generic names (.empty, .row-actions) have collided twice already. */
.mk-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:16px;align-items:start;margin-bottom:16px;}
/* MER-192: status filter chips on the Flow list pages */
.mk-status-chips{display:flex;flex-wrap:wrap;gap:6px;align-items:center;padding:.5rem .8rem;border-bottom:1px solid var(--im-border,#e5e7eb);font-size:12.5px;}
.mk-status-chips .lbl{color:#6b7480;font-weight:600;margin-right:2px;}
.mk-status-chips a{display:inline-flex;gap:6px;align-items:center;padding:3px 10px;border:1px solid #d7dde6;border-radius:999px;color:#3a4453;text-decoration:none;background:#fff;}
.mk-status-chips a:hover{border-color:#9aa5b4;}
.mk-status-chips a.on{background:#1f2937;border-color:#1f2937;color:#fff;}
.mk-status-chips a .n{font-size:11px;color:#8a93a0;font-variant-numeric:tabular-nums;}
.mk-status-chips a.on .n{color:#cbd5e1;}
.mk-status-chips .applied{margin-left:auto;color:#475569;}
.mk-status-chips .applied a{border:0;padding:0 2px;background:none;color:#1f6fe0;}
.mk-grid > *{min-width:0;}
.mk-span-1{grid-column:span 1;} .mk-span-2{grid-column:span 2;}
.mk-span-3{grid-column:span 3;} .mk-span-4{grid-column:span 4;}
.mk-grid.stretch{align-items:stretch;}
@media (max-width:1100px){
  .mk-grid{grid-template-columns:repeat(2,minmax(0,1fr));}
  .mk-span-3,.mk-span-4{grid-column:span 2;}
}
@media (max-width:640px){
  .mk-grid{grid-template-columns:minmax(0,1fr);}
  .mk-span-2,.mk-span-3,.mk-span-4{grid-column:span 1;}
}

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
    padding: .7rem 1rem;
    border-radius: 6px;
    font-size: .875rem;
    margin-bottom: 1rem;
    display: flex; align-items: flex-start; gap: .5rem;
}
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.alert-error   { background: var(--red-pale); border: 1px solid #fca5a5; color: var(--red); }
.alert-info    { background: var(--blue-pale); border: 1px solid #bfdbfe; color: var(--blue-dark); }

/* ── Module cards (dashboard) ──────────────────────────────── */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.module-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    padding: 1.25rem 1rem;
    text-decoration: none; color: inherit;
    transition: box-shadow .15s, border-color .15s;
    display: block;
}
.module-card:hover { box-shadow: var(--shadow-md); border-color: #93c5fd; text-decoration: none; }
.module-card-icon  { font-size: 1.75rem; margin-bottom: .6rem; }
.module-card-title { font-weight: 700; font-size: .95rem; color: var(--text); }
.module-card-desc  { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; line-height: 1.5; }
.module-card-badge { margin-top: .5rem; }

/* ── Module chips ──────────────────────────────────────────── */
.module-chip {
    display: inline-flex; align-items: center; gap: .3rem;
    font-size: .75rem; padding: .2rem .55rem;
    border-radius: 20px; font-weight: 500;
}
.module-chip.on  { background: #dcfce7; color: #15803d; }
.module-chip.off { background: #f1f5f9; color: var(--text-muted); text-decoration: line-through; }

/* ── Login page ────────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg);
}
.login-card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    width: 100%; max-width: 380px;
}
.login-logo h1 { font-size: 1.75rem; font-weight: 700; color: var(--blue); letter-spacing: -.5px; text-align: center; }
.login-logo p  { font-size: .8rem; color: var(--text-muted); text-align: center; margin-top: .25rem; margin-bottom: 1.75rem; }

/* ── Misc helpers ──────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: .8rem; }
.fw-600      { font-weight: 600; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.flex-end { justify-content: flex-end; }
.flex-between { justify-content: space-between; }

/* MER-91 / MER-268: template pages - one card per module, one block per type, one line per template with its state */
.tpl-legend{display:flex;gap:1.1rem;flex-wrap:wrap;align-items:center;font-size:.8rem;color:#6b7480;margin:0 0 .9rem;}
.tpl-module{background:#fff;border:1px solid var(--im-border,#e5e7eb);border-radius:10px;margin-bottom:1.2rem;overflow:hidden;box-shadow:0 1px 2px rgba(15,23,42,.04);}
.tpl-module-head{display:flex;align-items:baseline;gap:.6rem;padding:.7rem 1rem;background:#eef2f7;border-bottom:1px solid var(--im-border,#e5e7eb);border-left:5px solid var(--primary,#2563eb);}
.tpl-module-head .t{font-weight:800;font-size:1rem;letter-spacing:.01em;color:#0f172a;}
.tpl-module-head .n{color:#6b7480;font-size:.8rem;}
.tpl-type{padding:.75rem 1rem .7rem;border-top:1px solid #e5e7eb;}
.tpl-type:first-of-type{border-top:0;}
.tpl-type-head{display:flex;gap:.8rem;align-items:baseline;justify-content:space-between;margin-bottom:.4rem;}
.tpl-type-head > :first-child{flex:1 1 auto;min-width:0;}
.tpl-type-head > .btn{flex:0 0 auto;white-space:nowrap;}
.tpl-type-head .name{font-weight:700;font-size:.92rem;color:#0f172a;margin-right:.4rem;}
.tpl-type-head .desc{color:#6b7480;font-size:.78rem;}
.tpl-line{display:grid;grid-template-columns:7rem minmax(0,1fr) 10.5rem auto;gap:.7rem;align-items:start;padding:.45rem .6rem .45rem .8rem;margin-left:.9rem;border-left:3px solid #e2e8f0;font-size:.83rem;}
.tpl-line + .tpl-line{border-top:1px dashed #e8edf3;}
.tpl-line.in-use{border-left-color:#16a34a;background:#f4fbf6;}
.tpl-state{display:inline-block;font-size:.66rem;font-weight:800;letter-spacing:.05em;text-transform:uppercase;border-radius:4px;padding:.14rem .45rem;white-space:nowrap;}
.tpl-state.on{background:#16a34a;color:#fff;}
.tpl-state.off{background:#fff;color:#64748b;border:1px solid #cbd5e1;}
.tpl-line .meta{color:#6b7480;font-size:.78rem;}
.tpl-line .acts{display:flex;flex-wrap:wrap;gap:.3rem;justify-content:flex-end;align-items:center;}
.tpl-line .acts form{margin:0;}
@media (max-width:900px){.tpl-line{grid-template-columns:1fr;}.tpl-line .acts{justify-content:flex-start;}.tpl-type-head{flex-wrap:wrap;}}
