/* Shared design system for the NDIS Admin + Staff apps.
   Tokens, typography, forms, buttons, badges, cards, tables, navigation items
   and dashboard widgets live here; style.css (admin) and staff.css (staff)
   only add each app's layout shell. */

:root {
    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --color-bg: #f4f6f9;
    --color-surface: #ffffff;
    --color-surface-muted: #f8fafc;
    --color-border: #e3e7ee;
    --color-border-strong: #cbd3de;
    --color-text: #0e1a2b;
    --color-text-soft: #3b4859;
    --color-muted: #647084;

    /* Logo blue for accents/icons; the slightly deeper "action" shade is used
       wherever white text sits on blue so it stays AA-legible. */
    --color-primary: #0d9fde;
    --color-action: #0878ab;
    --color-action-hover: #066590;
    --color-primary-dark: #0878ab;
    --color-primary-soft: #e5f5fc;
    --color-ring: rgba(13, 159, 222, 0.30);

    --color-success: #1f7a55;
    --color-success-soft: #e6f4ed;
    --color-warning: #9a5b00;
    --color-warning-soft: #fbf0dc;
    --color-danger: #b42318;
    --color-danger-soft: #fdecea;
    --color-neutral: #647084;
    --color-neutral-soft: #eceff3;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;

    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 6px 12px -4px rgba(16, 24, 40, 0.10), 0 2px 4px -2px rgba(16, 24, 40, 0.05);
    --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, 0.18), 0 4px 8px -4px rgba(16, 24, 40, 0.06);

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

img { max-width: 100%; }

h1, h2, h3, h4 { color: var(--color-text); line-height: 1.25; letter-spacing: -0.015em; }
h2 { font-size: 22px; font-weight: 700; margin: 4px 0 16px; letter-spacing: -0.02em; }
h3 { font-size: 16px; font-weight: 650; }

a { color: var(--color-action); text-decoration: none; }
a:hover { color: var(--color-action-hover); }
a:not([class]):hover { text-decoration: underline; text-underline-offset: 3px; }

::selection { background: var(--color-ring); }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Forms ---------- */
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-soft);
    margin-bottom: 6px;
}

input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
input[type=time], input[type=datetime-local], input[type=tel], input[type=search], input[type=url],
select, textarea {
    display: block;
    width: 100%;
    padding: 10px 12px;
    min-height: 44px;
    margin-bottom: 16px;
    border: 1px solid var(--color-border-strong);
    border-radius: 10px;
    background-color: #fff;
    color: var(--color-text);
    font: inherit;
    font-size: 14.5px;
    line-height: 1.4;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

input::placeholder, textarea::placeholder { color: #98a2b3; }

input:hover, select:hover, textarea:hover { border-color: #aeb9c8; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px var(--color-ring);
}

input:disabled, select:disabled, textarea:disabled { background: var(--color-surface-muted); color: var(--color-muted); cursor: not-allowed; }

select {
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23647084' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

textarea { resize: vertical; min-height: 96px; }

input[type=checkbox], input[type=radio] {
    width: 18px;
    height: 18px;
    min-height: 0;
    margin: 0 6px 0 0;
    padding: 0;
    accent-color: var(--color-action);
    vertical-align: -3px;
    box-shadow: none;
    -webkit-appearance: auto;
    appearance: auto;
}

input[type=file] {
    padding: 8px;
    background: var(--color-surface-muted);
    border-style: dashed;
    font-size: 13.5px;
    color: var(--color-text-soft);
}
input[type=file]::file-selector-button {
    margin-right: 12px;
    padding: 7px 14px;
    border: 1px solid var(--color-border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--color-text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.form-row { display: flex; gap: 16px; }
.form-row > div { flex: 1; min-width: 0; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--color-action);
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
    text-decoration: none;
    box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, 0.14);
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .06s ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--color-action-hover); color: #fff; text-decoration: none; }
.btn:active { transform: translateY(1px); box-shadow: var(--shadow-xs); }
.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-secondary {
    background: #fff;
    color: var(--color-text);
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--color-surface-muted); color: var(--color-text); border-color: #aeb9c8; }

.btn-block { width: 100%; }

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid;
    border-left-width: 4px;
    font-size: 14px;
    margin-bottom: 16px;
}
.alert-error { background: var(--color-danger-soft); color: #8a1b12; border-color: #f4c3bd; border-left-color: var(--color-danger); }
.alert-success { background: var(--color-success-soft); color: #165c3f; border-color: #bde0cd; border-left-color: var(--color-success); }
.alert a { font-weight: 600; text-decoration: underline; color: inherit; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-muted { background: var(--color-neutral-soft); color: var(--color-muted); }

/* ---------- Cards & panels ---------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-xs);
}
.card > :last-child { margin-bottom: 0; }
.card > h3:first-child { margin-top: 0; }
.card p { margin: 0 0 10px; line-height: 1.55; }
.card p > strong:first-child { font-weight: 600; color: var(--color-text-soft); }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 14px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--color-muted);
}
.back-link:hover { color: var(--color-action); }

.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
    margin-bottom: 16px;
}
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}
.panel-header h3 { margin: 0; font-size: 15px; }
.panel-header a { font-size: 13px; font-weight: 600; }
.panel-empty { padding: 32px 20px; text-align: center; color: var(--color-muted); font-size: 14px; }

.activity-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--color-border);
    color: inherit;
    transition: background-color .15s ease;
}
.activity-row:last-child { border-bottom: none; }
a.activity-row:hover { background: var(--color-surface-muted); color: inherit; }
.activity-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.activity-icon svg { width: 17px; height: 17px; }
.activity-body { flex: 1; min-width: 0; }
.activity-title { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.activity-meta { font-size: 12.5px; color: var(--color-muted); margin-top: 2px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-muted);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
td { text-align: left; padding: 14px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color .12s ease; }
tbody tr:hover td { background: var(--color-surface-muted); }
td[colspan] { text-align: center; color: var(--color-muted); padding: 32px 14px; }
tbody tr:has(td[colspan]):hover td { background: transparent; }

/* ---------- Sidebar navigation (shared item styling) ---------- */
.sidebar { background: var(--color-surface); border-right: 1px solid var(--color-border); scrollbar-width: thin; scrollbar-color: var(--color-border-strong) transparent; }
.nav-group-label {
    padding: 18px 22px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #8a95a8;
}
.sidebar a.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 2px 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--color-text-soft);
    font-size: 14px;
    font-weight: 500;
    transition: background-color .15s ease, color .15s ease;
}
.sidebar a.nav-link svg { width: 19px; height: 19px; flex-shrink: 0; color: #8a95a8; transition: color .15s ease; }
.sidebar a.nav-link:hover { background: var(--color-surface-muted); color: var(--color-text); text-decoration: none; }
.sidebar a.nav-link:hover svg { color: var(--color-action); }
.sidebar a.nav-link.active { background: var(--color-primary-soft); color: var(--color-action); font-weight: 650; }
.sidebar a.nav-link.active svg { color: var(--color-primary); }
.sidebar a.nav-link.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 9px;
    bottom: 9px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--color-primary);
}

/* ---------- Top bar pieces shared by both apps ---------- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}
.brand-logo { height: 36px; width: auto; background: #fff; border-radius: 8px; padding: 3px 7px; display: block; }

/* ---------- Dashboard widgets ---------- */
.dash-header { margin-bottom: 22px; }
.dash-header h1 { font-size: 26px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.025em; }
.dash-header p { margin: 0; color: var(--color-muted); font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 24px; }
.stat-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px;
    color: inherit;
    box-shadow: var(--shadow-xs);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--color-border-strong); color: inherit; }
a.stat-card:active { transform: translateY(0); }

.stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
}
.stat-icon svg { width: 19px; height: 19px; }
.stat-icon--primary { background: var(--color-primary-soft); color: var(--color-action); }
.stat-icon--success { background: var(--color-success-soft); color: var(--color-success); }
.stat-icon--warning { background: var(--color-warning-soft); color: var(--color-warning); }
.stat-icon--danger { background: var(--color-danger-soft); color: var(--color-danger); }
.stat-icon--neutral { background: var(--color-neutral-soft); color: var(--color-neutral); }

.stat-value { font-size: 28px; font-weight: 700; line-height: 1.1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--color-muted); font-size: 13px; margin-top: 4px; }

.dash-hero {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-primary);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}
.dash-hero--active { border-left-color: var(--color-success); }
.dash-hero-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 700; color: var(--color-muted); margin-bottom: 4px; }
.dash-hero-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 16px; color: var(--color-text); }
.dash-hero .btn { margin-bottom: 0; }

.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 6px;
    color: var(--color-text);
    font-size: 12.5px;
    font-weight: 600;
    text-align: center;
    box-shadow: var(--shadow-xs);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.quick-action:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); border-color: var(--color-border-strong); color: var(--color-text); }
.quick-action svg { width: 22px; height: 22px; color: var(--color-primary); }

/* ---------- List cards (mobile replacement for tables) ---------- */
.list-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    color: inherit;
    box-shadow: var(--shadow-xs);
    transition: transform .12s ease, box-shadow .15s ease, border-color .15s ease;
}
a.list-card:hover { box-shadow: var(--shadow-md); border-color: var(--color-border-strong); color: inherit; }
a.list-card:active { transform: scale(0.992); }
.list-card-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 4px; font-size: 15px; font-weight: 650; }
.list-card-meta { font-size: 13px; color: var(--color-muted); line-height: 1.55; }
.list-card-empty { text-align: center; color: var(--color-muted); padding: 32px 0; }

/* ---------- "More" menu rows ---------- */
.menu-list { padding: 6px 8px; }
.menu-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 8px;
    border-radius: 10px;
    color: var(--color-text);
    font-size: 15px;
    transition: background-color .12s ease;
}
.menu-list a:active, .menu-list a:hover { background: var(--color-surface-muted); color: var(--color-text); }
.menu-list-label { display: flex; align-items: center; gap: 14px; font-weight: 550; }
.menu-list-label svg { width: 38px; height: 38px; padding: 9px; border-radius: 10px; background: var(--color-primary-soft); color: var(--color-action); flex-shrink: 0; }
.menu-list-chevron { color: #aab3c2; flex-shrink: 0; }

/* ---------- Signature canvas ---------- */
.signature-wrap { width: 100%; }
.signature-wrap canvas {
    display: block;
    width: 100%;
    max-width: 100%;
    height: 170px;
    border: 1.5px dashed var(--color-border-strong);
    border-radius: var(--radius);
    background: var(--color-surface-muted);
    touch-action: none;
}

/* ---------- Auth screens ---------- */
.auth-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
    background:
        radial-gradient(900px 420px at 50% -120px, rgba(13, 159, 222, 0.14), transparent 70%),
        var(--color-bg);
}
.auth-box {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 32px 28px 28px;
    box-shadow: var(--shadow-lg);
}
.auth-box h1 { font-size: 22px; margin: 0 0 4px; }
.auth-box p.subtitle { color: var(--color-muted); margin: 0 0 22px; font-size: 14px; }
.auth-box .btn { margin-top: 4px; }

/* ---------- Desktop refinements ---------- */
@media (min-width: 900px) {
    body { font-size: 14.5px; }
    input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
    input[type=time], input[type=datetime-local], input[type=tel], input[type=search], input[type=url],
    select, textarea { font-size: 14px; min-height: 42px; }
    .stat-card { padding: 20px; }
    .stat-value { font-size: 30px; }
}

/* Touch devices: 16px inputs prevent iOS focus-zoom */
@media (max-width: 899px) {
    input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
    input[type=time], input[type=datetime-local], input[type=tel], input[type=search], input[type=url],
    select, textarea { font-size: 16px; }
}

/* ---------- Progress note: optional NDIS goals ---------- */
.goals-hint { color: var(--color-muted); font-size: 13.5px; margin: 0 0 14px; }
.goal-item {
    margin-bottom: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.goal-item.is-open { border-color: var(--color-primary); background: var(--color-primary-soft); box-shadow: 0 0 0 3px var(--color-ring); }
.goal-check {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 0;
    padding: 14px 16px;
    font-size: 14.5px;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
}
.goal-check input { margin: 2px 0 0; flex-shrink: 0; width: 20px; height: 20px; }
.goal-fields { display: none; padding: 0 16px 6px; }
.goal-item.is-open .goal-fields { display: block; }
.goal-fields textarea { background: #fff; }
.goal-custom { padding: 14px 16px 0; }
.goal-custom > input[type=text] { background: #fff; }
.goal-custom .goal-fields { padding: 0; }
.goal-custom-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.goal-custom-head label { margin: 0; }
.goal-remove { border: none; background: none; color: var(--color-danger); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.goal-remove:hover { background: var(--color-danger-soft); }
