/* =============================================================================
   Ledger — Stylesheet (emerald-branded revamp)
   ============================================================================= */
/* Clean, modern accounting UI. Emerald brand, white surfaces, colour-coded
   companies and metric tiles. Tabular numerals for all figures. */

:root {
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;

    /* Brand — emerald */
    --brand: #0f4c45;          /* deep emerald — sidebar, primary buttons */
    --brand-accent: #1d9e75;   /* brighter emerald — active nav, highlights */
    --brand-soft: #e1f5ee;     /* pale emerald — soft fills */
    --brand-ink: #0f6e56;      /* emerald text on pale fills */
    --brand-deep: #04342c;     /* darkest emerald — figures on pale fills */

    /* Surfaces */
    --bg: #f4f6f5;             /* page background — faint cool grey-green */
    --paper: #ffffff;          /* cards, panels */
    --ink: #16201d;            /* primary text */
    --ink-soft: #5f6b67;       /* secondary text */
    --ink-faint: #8a948f;      /* tertiary / hints */
    --rule: #e3e8e6;           /* borders */
    --rule-soft: #eef1f0;      /* subtle dividers */
    --highlight: #f0f5f3;      /* hover */

    /* Semantic */
    --negative: #b3261e;       /* red — negative balances */
    --positive: #0f6e56;       /* emerald — positive */
    --warning: #854f0b;        /* amber text */
    --warning-soft: #faeeda;
    --info: #185fa5;           /* blue text */
    --info-soft: #e6f1fb;
    --coral: #993c1d;          /* coral text */
    --coral-soft: #faece7;

    --button: var(--brand);
    --button-text: #ffffff;

    --radius: 10px;
    --radius-sm: 7px;
}

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

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--brand-ink);
    text-decoration: none;
    transition: color 0.15s;
}
a:hover { color: var(--brand-accent); }

h1, h2, h3, h4 {
    font-family: var(--font-body);
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--ink);
}
h1 { font-size: 1.6rem; line-height: 1.2; }
h2 { font-size: 1.25rem; margin-bottom: 0.75rem; }
h3 { font-size: 1.05rem; margin-bottom: 0.5rem; }
p { margin-bottom: 0.75rem; }

/* =============================================================================
   Layout
   ============================================================================= */
.app-shell {
    display: grid;
    grid-template-columns: 210px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--brand);
    padding: 1.4rem 0.75rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 1.3rem;
    font-weight: 600;
    color: #fff;
    padding: 0 0.5rem 0.2rem;
    letter-spacing: -0.02em;
}
.brand::before {
    content: "";
    width: 26px; height: 26px;
    border-radius: 7px;
    background: var(--brand-accent);
    flex-shrink: 0;
}
.brand .dot { display: none; }
.brand-sub {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #9fd8c9;
    padding: 0 0.5rem;
    margin-bottom: 1.5rem;
}

.nav-section { margin-bottom: 1.25rem; }
.nav-label {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: #6fb3a2;
    margin-bottom: 0.4rem;
    padding-left: 0.6rem;
}
.nav-section ul { list-style: none; }
.nav-section a {
    display: block;
    padding: 0.5rem 0.65rem;
    text-decoration: none;
    color: #c8e6dd;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 1px;
    transition: background 0.12s, color 0.12s;
}
.nav-section a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-section a.active { background: var(--brand-accent); color: #fff; }

.main {
    padding: 1.75rem 2.25rem 4rem;
    max-width: 1300px;
}

.page-header {
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 1rem;
    border-bottom: 1px solid var(--rule);
}
.page-title-block .crumb {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    margin-bottom: 0.35rem;
}
.page-title-block .crumb a { color: var(--ink-faint); }
.page-title-block .crumb a:hover { color: var(--brand-accent); }

/* =============================================================================
   Metric tiles (dashboard summary numbers)
   ============================================================================= */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 1.5rem;
}
.metric {
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    background: var(--brand-soft);
}
.metric .label {
    display: flex; align-items: center; gap: 7px;
    font-size: 0.8rem;
    color: var(--brand-ink);
}
.metric .value {
    font-size: 1.7rem;
    font-weight: 600;
    color: var(--brand-deep);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}
.metric.blue { background: var(--info-soft); }
.metric.blue .label { color: var(--info); }
.metric.blue .value { color: #042c53; }
.metric.amber { background: var(--warning-soft); }
.metric.amber .label { color: var(--warning); }
.metric.amber .value { color: #412402; }
.metric.coral { background: var(--coral-soft); }
.metric.coral .label { color: var(--coral); }
.metric.coral .value { color: #4a1b0c; }

/* =============================================================================
   Tables
   ============================================================================= */
table {
    border-collapse: collapse;
    width: 100%;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.9rem;
}
th, td {
    text-align: left;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--rule-soft);
    vertical-align: top;
}
th {
    font-weight: 600;
    background: var(--brand);
    color: #c8e6dd;
    border-bottom: 1px solid var(--brand);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--highlight); }

/* Date column: keep dates on one line and give them room */
td.date, th.date {
    white-space: nowrap;
    width: 7rem;
}

td.num, th.num {
    text-align: right;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.875rem;
}
td.code, th.code {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--ink-soft);
    width: 5rem;
}
td.muted { color: var(--ink-soft); }
td.negative, .negative { color: var(--negative); }

.tag {
    display: inline-block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.2rem 0.5rem;
    background: var(--brand-soft);
    color: var(--brand-ink);
    border-radius: 100px;
    font-weight: 600;
}
.tag.reversed { background: var(--coral-soft); color: var(--coral); }

/* =============================================================================
   Cards
   ============================================================================= */
.card {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: 1.5rem;
}

.entity-card {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-top: 3px solid var(--brand-accent);
    border-radius: var(--radius);
    padding: 1.2rem 1.25rem;
    text-decoration: none;
    color: var(--ink);
    display: block;
    transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
}
.entity-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(15,76,69,0.08);
    text-decoration: none;
    color: var(--ink);
}
/* per-company accent colours (cycle) */
.entity-card:nth-child(3n+2) { border-top-color: #378add; }
.entity-card:nth-child(3n)   { border-top-color: #d85a30; }

.entity-card .avatar {
    width: 38px; height: 38px; border-radius: 9px;
    background: var(--brand-soft); color: var(--brand-ink);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 600; margin-bottom: 0.75rem;
}
.entity-card:nth-child(3n+2) .avatar { background: var(--info-soft); color: var(--info); }
.entity-card:nth-child(3n) .avatar { background: var(--coral-soft); color: var(--coral); }

.entity-card .code {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-faint);
}
.entity-card .name {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0.15rem 0 0.5rem;
}
.entity-card .meta {
    font-size: 0.78rem;
    color: var(--ink-soft);
    margin-bottom: 0.75rem;
    display: flex; gap: 0.5rem; flex-wrap: wrap;
}
.entity-card .stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem 1rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--rule-soft);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
}
.entity-card .stats .label {
    color: var(--ink-soft);
    font-family: var(--font-body);
    font-size: 0.72rem;
}

/* =============================================================================
   Forms
   ============================================================================= */
.form-grid {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 1rem 1.5rem;
    align-items: start;
    margin-bottom: 1.5rem;
}
label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink);
    line-height: 2.2;
}
label .hint {
    display: block;
    font-weight: 400;
    color: var(--ink-soft);
    font-size: 0.75rem;
    line-height: 1.4;
    margin-top: 0.1rem;
}
input[type="text"], input[type="number"], input[type="date"],
input[type="password"], select, textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--rule);
    background: var(--paper);
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--ink);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="number"], input[type="date"], .num-input {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(29,158,117,0.15);
}
textarea { min-height: 80px; resize: vertical; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.55rem 1.1rem;
    background: var(--button);
    color: var(--button-text);
    border: 1px solid var(--button);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.15s, transform 0.1s;
}
.btn:hover { background: var(--brand-accent); border-color: var(--brand-accent); color: #fff; text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn.secondary {
    background: var(--paper);
    color: var(--ink);
    border-color: var(--rule);
}
.btn.secondary:hover { background: var(--highlight); color: var(--ink); border-color: var(--brand-accent); }
.btn.danger { background: var(--negative); border-color: var(--negative); }
.btn.danger:hover { background: #8c1d17; border-color: #8c1d17; }

.btn-row {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--rule);
}

.lines-table input, .lines-table select { padding: 0.4rem 0.55rem; font-size: 0.85rem; }
.lines-table .num-input { text-align: right; }

/* =============================================================================
   Alerts
   ============================================================================= */
.alert {
    padding: 0.8rem 1rem;
    border: 1px solid var(--rule);
    border-left: 3px solid var(--ink-soft);
    background: var(--paper);
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert.warning { border-left-color: var(--warning); background: var(--warning-soft); }
.alert.success { border-left-color: var(--positive); background: var(--brand-soft); }
.alert.info { border-left-color: var(--info); background: var(--info-soft); }
.alert.error, .alert.danger { border-left-color: var(--negative); background: #fceceb; }

/* =============================================================================
   Login screen
   ============================================================================= */
.login-container {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: var(--brand);
}
.login-box {
    width: 360px;
    background: var(--paper);
    border-radius: var(--radius);
    padding: 2rem 2.5rem;
}
.login-box .brand { color: var(--brand); justify-content: center; margin-bottom: 0.25rem; }
.login-box .brand-sub { text-align: center; color: var(--ink-soft); margin-bottom: 2rem; }
.login-box label { display: block; margin-bottom: 0.25rem; line-height: 1.4; }
.login-box .form-row { margin-bottom: 1rem; }
.login-box .btn { width: 100%; padding: 0.7rem; justify-content: center; }

/* =============================================================================
   Utility
   ============================================================================= */
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); }
.positive { color: var(--positive); }
.small { font-size: 0.8rem; }
.uppercase { text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.75rem; }
.flex-row { display: flex; gap: 1rem; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-sm { gap: 0.5rem; }
hr.rule { border: none; border-top: 1px solid var(--rule); margin: 1.25rem 0; }
footer {
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 1px solid var(--rule);
    font-size: 0.75rem;
    color: var(--ink-faint);
    text-align: center;
}

/* Phase 18B — user admin */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    font-size: 0.72rem;
    border-radius: 0.85rem;
    background: var(--surface-2, #2a2a2a);
    color: var(--text, #d4d4d4);
    border: 1px solid var(--border, #444);
}
.badge.admin {
    background: var(--brand-soft, #1a2438);
    border-color: var(--brand, #4a90e2);
    color: var(--brand, #4a90e2);
}
