:root {
    color-scheme: light;
    --navy: #102a43;
    --navy-soft: #243b53;
    --blue: #1363df;
    --blue-dark: #0b4fb3;
    --cyan: #e8f3ff;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --line: #d9e2ec;
    --text: #243b53;
    --muted: #627d98;
    --green: #16815d;
    --green-bg: #e7f8f1;
    --amber: #b7791f;
    --amber-bg: #fff7df;
    --red: #c0392b;
    --red-bg: #fff0ed;
    --shadow: 0 12px 36px rgba(16, 42, 67, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }

button {
    min-height: 40px;
    padding: 9px 15px;
    border: 1px solid var(--blue);
    border-radius: 8px;
    color: #fff;
    background: var(--blue);
    cursor: pointer;
    font-weight: 650;
}

button:hover { background: var(--blue-dark); }
button:disabled { opacity: .55; cursor: wait; }
button.secondary { color: var(--navy); background: #fff; border-color: var(--line); }
button.secondary:hover { background: #f7f9fc; }

input, select, textarea {
    width: 100%;
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
    color: var(--text);
    background: #fff;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(19, 99, 223, .12);
}

textarea { resize: vertical; line-height: 1.45; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 22px 30px;
    color: #fff;
    background: linear-gradient(120deg, var(--navy), #174f78);
}

.topbar h1 { margin: 3px 0 4px; font-size: 25px; letter-spacing: -.4px; }
.topbar p { margin: 0; color: #c8d9e8; }
.eyebrow, .section-label { font-size: 11px; font-weight: 800; letter-spacing: 1.3px; text-transform: uppercase; }
.eyebrow { color: #82c4ff; }
.section-label { color: var(--blue); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 8px;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
}
.nav-link:hover { background: rgba(255,255,255,.1); }

.health {
    padding: 7px 11px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    font-size: 12px;
    font-weight: 750;
}
.health.up { color: #b9f6dc; }
.health.down { color: #ffd0ca; }

main { padding: 20px 30px 34px; }

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stats article {
    min-width: 0;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.stats span { display: block; color: var(--muted); font-size: 12px; font-weight: 650; }
.stats strong { display: block; margin-top: 7px; color: var(--navy); font-size: 25px; overflow-wrap: anywhere; }
#lastBusinessKey { font-size: 15px; line-height: 1.5; }

.workspace {
    display: grid;
    grid-template-columns: minmax(280px, .72fr) minmax(310px, .78fr) minmax(500px, 1.5fr);
    gap: 16px;
    align-items: start;
}

.panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 17px 18px;
    border-bottom: 1px solid var(--line);
}

h2, h3 { margin: 0; color: var(--navy); }
.panel h2 { margin-top: 3px; font-size: 18px; }
.task-head select { width: 145px; }

.preset-row { display: flex; gap: 7px; padding: 14px 18px 0; }
.preset { min-height: 34px; padding: 6px 11px; color: var(--muted); background: #fff; border-color: var(--line); font-size: 12px; }
.preset.active, .preset:hover { color: var(--blue); background: var(--cyan); border-color: #9ecbff; }

.form-grid { display: grid; gap: 13px; }
.create-panel .form-grid { padding: 15px 18px 18px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { display: grid; gap: 8px; margin: 0; padding: 11px; border: 1px solid var(--line); border-radius: 8px; }
legend { padding: 0 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; accent-color: var(--blue); }

.result-box {
    margin: 0 18px 18px;
    padding: 12px;
    border: 1px solid #9de0c5;
    border-radius: 8px;
    color: var(--green);
    background: var(--green-bg);
    font-size: 13px;
    line-height: 1.5;
}

.task-list { display: grid; gap: 9px; padding: 13px; max-height: 710px; overflow: auto; }
.task-card {
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 9px;
    cursor: pointer;
    transition: border-color .15s, transform .15s, background .15s;
}
.task-card:hover { transform: translateY(-1px); border-color: #9ecbff; }
.task-card.active { border-color: var(--blue); background: #f4f9ff; box-shadow: inset 3px 0 0 var(--blue); }
.task-card h3 { margin: 7px 0; font-size: 14px; }
.task-card p { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.task-card footer { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 11px; }

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 23px;
    padding: 3px 8px;
    border-radius: 999px;
    color: var(--blue);
    background: var(--cyan);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}
.pill.manager { color: #8b4b15; background: var(--amber-bg); }

.empty-state { padding: 80px 30px; text-align: center; color: var(--muted); }
.empty-state h2 { margin: 14px 0 7px; }
.empty-state p { max-width: 380px; margin: auto; line-height: 1.5; }
.empty-icon {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    margin: auto;
    border-radius: 16px;
    color: var(--blue);
    background: var(--cyan);
    font-weight: 850;
}

.detail-title { display: flex; align-items: start; justify-content: space-between; gap: 16px; padding: 20px; border-bottom: 1px solid var(--line); }
.detail-title h2 { margin: 7px 0 4px; font-size: 20px; }
.detail-title p { margin: 0; color: var(--muted); font-size: 12px; }
.detail-section { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.detail-section:last-child { border-bottom: 0; }
.detail-section h3 { margin-bottom: 13px; font-size: 15px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading span { color: var(--blue); font-size: 12px; font-weight: 700; }

.workflow-map { display: grid; grid-template-columns: repeat(4, minmax(80px, 1fr)); gap: 9px; }
.workflow-step {
    position: relative;
    min-height: 67px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbfd;
}
.workflow-step span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.workflow-step strong { font-size: 12px; line-height: 1.35; }
.workflow-step.completed { border-color: #91d8bc; background: var(--green-bg); }
.workflow-step.completed span { color: var(--green); }
.workflow-step.active { color: #fff; border-color: var(--blue); background: var(--blue); box-shadow: 0 6px 15px rgba(19,99,223,.22); }
.workflow-step.active span { color: #d8eaff; }
.workflow-step.branch { border-style: dashed; }

.data-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.data-item { min-width: 0; padding: 10px 11px; border-radius: 8px; background: #f7f9fc; }
.data-item.wide { grid-column: 1 / -1; }
.data-item span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 750; text-transform: uppercase; }
.data-item strong { display: block; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.decision-section { background: #fbfdff; }
.decision-section .form-grid { padding: 0; }

.empty-list { padding: 38px 20px; color: var(--muted); text-align: center; line-height: 1.5; }
.hidden { display: none !important; }

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    max-width: min(420px, calc(100vw - 44px));
    padding: 12px 15px;
    border-radius: 9px;
    color: #fff;
    background: var(--navy);
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }

@media (max-width: 1250px) {
    .workspace { grid-template-columns: minmax(280px, .8fr) minmax(420px, 1.2fr); }
    .detail-panel { grid-column: 1 / -1; }
}

@media (max-width: 820px) {
    .topbar, .top-actions { align-items: stretch; flex-direction: column; }
    main { padding: 15px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .workspace { grid-template-columns: 1fr; }
    .detail-panel { grid-column: auto; }
    .workflow-map { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
    .topbar { padding: 18px; }
    .stats, .two-col, .data-grid { grid-template-columns: 1fr; }
    .data-item.wide { grid-column: auto; }
    .detail-title, .section-heading { align-items: stretch; flex-direction: column; }
}
