/* Colors and type follow ferraratransport.com: white header, navy text, brand blue */
:root {
    --blue: #0067b2;
    --blue-dark: #00528e;
    --navy: #06163a;
    --ink: #1d2330;
    --muted: #5d6675;
    --line: #dde2ea;
    --bg: #f4f6f9;
    --card: #ffffff;
    --danger: #b42318;
    --danger-bg: #fdecea;
    --ok: #18794e;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);

    --status-draft: #5d6675;     --status-draft-bg: #eef0f3;
    --status-sent: #0069b1;      --status-sent-bg: #e3f0fa;
    --status-accepted: #18794e;  --status-accepted-bg: #e3f5ec;
    --status-declined: #b42318;  --status-declined-bg: #fdecea;

    color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.45 Cabin, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

h1 { font-size: 1.45rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }

.boot { padding: 3rem; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------ top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .45rem max(1rem, env(safe-area-inset-right)) .45rem max(1rem, env(safe-area-inset-left));
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    color: var(--navy);
}
.topbar .brand { display: flex; align-items: center; white-space: nowrap; }
.topbar .brand img { height: 42px; display: block; }
.topbar nav { display: flex; gap: .25rem; flex: 1; margin-left: .75rem; }
.topbar nav a {
    color: var(--navy);
    padding: .5rem .8rem;
    font-weight: 600;
    font-size: 1rem;
    border-bottom: 3px solid transparent;
}
.topbar nav a:hover { color: var(--blue); text-decoration: none; }
.topbar nav a.active { color: var(--blue); border-bottom-color: var(--blue); }

.usermenu { position: relative; }
.usermenu > button {
    background: #fff;
    border: 1px solid #c9d0db;
    color: var(--navy);
    border-radius: 999px;
    padding: .3rem .8rem;
    font: inherit;
    font-size: .85rem;
    cursor: pointer;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.usermenu .menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 200px;
    background: var(--card);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(16, 24, 40, .15);
    padding: .35rem;
    display: none;
}
.usermenu.open .menu { display: block; }
.usermenu .menu .who { padding: .4rem .6rem; font-size: .8rem; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: .25rem; }
.usermenu .menu a, .usermenu .menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: .45rem .6rem;
    border-radius: 6px;
    color: var(--ink);
    background: none;
    border: 0;
    font: inherit;
    cursor: pointer;
}
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--bg); text-decoration: none; }
.usermenu .menu [hidden] { display: none; }

/* ------------------------------------------------------------ layout */

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.25rem max(1rem, env(safe-area-inset-left)) 3rem;
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
}
.page-head h1 { flex: 1; min-width: 0; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: .2rem; font-weight: normal; }
.back { display: inline-block; margin-bottom: .5rem; font-size: .9rem; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1rem;
}
.card.flush { padding: 0; overflow: hidden; }
.card .card-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.card .card-head h2 { margin: 0; flex: 1; }

.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar .search { flex: 1; min-width: 200px; }

.loading, .empty { padding: 2rem; text-align: center; color: var(--muted); }

.error-box {
    background: var(--danger-bg);
    color: var(--danger);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
}

/* ------------------------------------------------------------ forms */

label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }

input, select, textarea {
    width: 100%;
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid #c9d0db;
    border-radius: 6px;
    padding: .5rem .65rem;
    min-height: 38px;
}
textarea { min-height: 70px; resize: vertical; }
input[type=search] { -webkit-appearance: none; appearance: none; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(0, 105, 177, .35); border-color: var(--blue); }
input:disabled, select:disabled, textarea:disabled { background: #f6f7f9; color: var(--ink); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }

.field { margin-bottom: .85rem; }
.grid { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

.input-suffix { position: relative; }
.input-suffix input { padding-right: 2.2rem; }
.input-suffix span { position: absolute; right: .7rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-prefix { position: relative; }
.input-prefix input { padding-left: 1.5rem; }
.input-prefix span { position: absolute; left: .65rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

.segmented { display: inline-flex; border: 1px solid #c9d0db; border-radius: 6px; overflow: hidden; margin-bottom: .85rem; }
.segmented label {
    margin: 0;
    padding: .4rem .9rem;
    font-size: .88rem;
    color: var(--ink);
    font-weight: 500;
    cursor: pointer;
    background: #fff;
}
.segmented label + label { border-left: 1px solid #c9d0db; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--blue); color: #fff; }

.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .5rem; }
.form-actions .spacer { flex: 1; }

/* ------------------------------------------------------------ buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    font: inherit;
    font-weight: 600;
    font-size: .9rem;
    padding: .5rem .95rem;
    min-height: 38px;
    border-radius: 6px;
    border: 1px solid #c9d0db;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: #f3f5f8; text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { padding: .25rem .6rem; min-height: 30px; font-size: .82rem; }
.btn.link { border: 0; background: none; color: var(--blue); padding: 0; min-height: 0; font-weight: 500; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn:disabled { opacity: .55; cursor: default; }

/* ------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th {
    text-align: left;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    font-weight: 600;
    padding: .6rem .8rem;
    border-bottom: 1px solid var(--line);
    background: #fafbfc;
    white-space: nowrap;
}
table.list td { padding: .65rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: #f7f9fc; }
table.list .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.list .nowrap { white-space: nowrap; }
table.list .muted, .muted { color: var(--muted); }
table.list .route { max-width: 340px; }
table.list .route small { display: block; color: var(--muted); }
table.list select { min-height: 30px; padding: .2rem .4rem; width: auto; font-size: .85rem; }

/* ------------------------------------------------------------ status badges */

.badge {
    display: inline-block;
    padding: .12rem .55rem;
    border-radius: 999px;
    font-size: .76rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge.draft    { color: var(--status-draft);    background: var(--status-draft-bg); }
.badge.sent     { color: var(--status-sent);     background: var(--status-sent-bg); }
.badge.accepted { color: var(--status-accepted); background: var(--status-accepted-bg); }
.badge.declined { color: var(--status-declined); background: var(--status-declined-bg); }
.badge.role     { color: var(--navy); background: #e8e9f5; }
.badges { display: flex; flex-wrap: wrap; gap: .3rem; }

select.status.draft    { color: var(--status-draft); }
select.status.sent     { color: var(--status-sent); }
select.status.accepted { color: var(--status-accepted); }
select.status.declined { color: var(--status-declined); }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chips a {
    padding: .3rem .75rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-size: .85rem;
    font-weight: 500;
}
.chips a:hover { text-decoration: none; border-color: #b8c1ce; }
.chips a.active { background: var(--navy); border-color: var(--navy); color: #fff; }

/* ------------------------------------------------------------ client details */

.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem 1.5rem; }
.details dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.details dd { margin: .1rem 0 0; white-space: pre-line; word-break: break-word; }

/* ------------------------------------------------------------ quote editor */

.quote-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.summary { position: sticky; top: 70px; }
.summary dl { margin: 0; }
.summary .row { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; font-variant-numeric: tabular-nums; }
.summary .row dt { color: var(--muted); }
.summary .row dd { margin: 0; text-align: right; }
.summary .row.total { border-top: 1px solid var(--line); margin-top: .35rem; padding-top: .6rem; font-weight: 700; }
.summary .price-field { margin-top: 1rem; }
.summary .price-field input { font-size: 1.3rem; font-weight: 700; }
.summary .actions { display: grid; gap: .5rem; margin-top: 1rem; }

.route-leg { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 0 .75rem; }
.miles-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; }
.miles-row .field { margin-bottom: 0; }
.miles-row .miles { width: 160px; }
.miles-status { font-size: .85rem; color: var(--muted); padding-bottom: .55rem; }
.miles-status.error { color: var(--danger); }

.new-client { border-left: 3px solid var(--blue); padding-left: 1rem; margin-top: .25rem; }

.route-map {
    height: 300px;
    margin-top: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: #e9edf2;
}
.route-map[hidden] { display: none; }

/* Address suggestions under the start and destination inputs */
.ac-wrap { position: relative; }
.ac-list {
    position: absolute;
    z-index: 20;
    left: 0;
    right: 0;
    top: calc(100% - .1rem);
    margin: 0;
    padding: .25rem 0;
    list-style: none;
    background: var(--card);
    border: 1px solid #c9d0db;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .15);
}
.ac-list li[data-i] { padding: .45rem .7rem; cursor: pointer; font-size: .92rem; line-height: 1.3; }
.ac-list li[data-i] span { color: var(--muted); font-size: .85rem; }
.ac-list li[data-i]:hover, .ac-list li.active { background: #eef4fa; }
.ac-list .ac-credit { padding: .3rem .7rem 0; font-size: .7rem; color: var(--muted); text-align: right; }

/* ------------------------------------------------------------ sign-in */

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .logo { display: block; width: 180px; margin: 0 auto 1.25rem; }
.auth-card h1 { text-align: center; margin-bottom: 1.1rem; font-size: 1.2rem; }
.auth-card .btn { width: 100%; }
.auth-card p { color: var(--muted); font-size: .9rem; }

/* ------------------------------------------------------------ dialog and toast */

dialog {
    border: 0;
    border-radius: 10px;
    padding: 1.25rem 1.3rem;
    width: min(440px, calc(100vw - 2rem));
    box-shadow: 0 20px 50px rgba(16, 24, 40, .3);
    color: var(--ink);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog h2 { margin-bottom: .5rem; }
dialog p { margin-top: 0; color: var(--muted); font-size: .92rem; }

#toast {
    position: fixed;
    left: 50%;
    bottom: calc(1.25rem + env(safe-area-inset-bottom));
    transform: translate(-50%, 1rem);
    background: var(--ink);
    color: #fff;
    padding: .6rem 1rem;
    border-radius: 8px;
    font-size: .9rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 100;
    max-width: calc(100vw - 2rem);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }

.password-reveal {
    font-family: ui-monospace, Consolas, monospace;
    background: var(--bg);
    padding: .5rem .7rem;
    border-radius: 6px;
    user-select: all;
}

/* ------------------------------------------------------------ small screens */

@media (max-width: 860px) {
    .quote-layout { grid-template-columns: 1fr; }
    .summary { position: static; }
}

@media (max-width: 640px) {
    .topbar { flex-wrap: wrap; gap: .5rem; }
    .topbar .brand span { display: none; }
    .topbar nav { order: 3; flex-basis: 100%; }
    .usermenu { margin-left: auto; }
    .grid.g2, .grid.g3, .grid.g4 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .route-leg { grid-template-columns: 1fr; }
    .hide-sm { display: none; }
    main { padding-top: 1rem; }
}
