:root {
    --navy: #1a365d;
    --text: #1e293b;
    --muted: #64748b;
    --line: #cbd5e1;
    --bg: #f1f5f9;
    --card: #ffffff;
    --error: #b91c1c;
    --ok-bg: #ecfdf5;
    --ok-line: #6ee7b7;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Liberation Sans", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
}
main {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px 16px 48px;
}
h1, h2 { color: var(--navy); margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: var(--navy);
    color: #fff;
}
.topbar .brand { font-weight: 700; letter-spacing: .5px; }
.topbar form { margin: 0; }

.card {
    background: var(--card);
    border-radius: 12px;
    padding: 18px 16px;
    margin-top: 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
}
.success {
    background: var(--ok-bg);
    border: 1px solid var(--ok-line);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}
.success p { margin: 0; }

label, legend {
    display: block;
    font-weight: 600;
    font-size: 14px;
    margin: 14px 0 6px;
    color: var(--navy);
}
fieldset { border: 0; margin: 14px 0 0; padding: 0; min-width: 0; }
fieldset:first-of-type { margin-top: 0; }
fieldset legend { margin-top: 0; padding: 0; }
.optional { font-weight: 400; color: var(--muted); }

input, select, textarea, button, .button {
    font: inherit;
    font-size: 16px; /* no zoom-on-focus on iOS */
}
input:not([type=radio]):not([type=checkbox]), select, textarea {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--navy);
    outline-offset: 1px;
}

.segmented { display: flex; gap: 8px; }
.segmented label { flex: 1; margin: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
    display: block;
    text-align: center;
    padding: 11px 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 600;
    color: var(--text);
    background: #fff;
    cursor: pointer;
}
.segmented input:checked + span { background: var(--navy); border-color: var(--navy); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--navy); outline-offset: 2px; }

.check {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: var(--text);
}
.check input { width: 22px; height: 22px; }

.custom-client {
    border-left: 3px solid var(--line);
    padding-left: 12px;
    margin-top: 6px;
}

.with-unit { position: relative; }
.with-unit input { padding-right: 36px; }
.with-unit span {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
}

.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.row > div { min-width: 0; }
input[type=date] { min-width: 0; -webkit-appearance: none; appearance: none; }
@media (max-width: 380px) { .row { grid-template-columns: 1fr; } }

.hint { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.hint:empty { display: none; }
.error { color: var(--error); font-size: 14px; margin: 6px 0 0; }

button, .button {
    display: inline-block;
    min-height: 44px;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--navy);
    background: #fff;
    color: var(--navy);
    font-weight: 600;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
}
button.primary, .button.primary { background: var(--navy); color: #fff; }
form > button.primary { width: 100%; margin-top: 22px; }
button:disabled { opacity: .6; cursor: wait; }
button.link {
    min-height: 0;
    padding: 4px 0;
    border: 0;
    background: none;
    color: #fff;
    text-decoration: underline;
}

.history { list-style: none; margin: 0; padding: 0; }
.history li {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
    align-items: center;
    padding: 12px 0;
    border-top: 1px solid #e2e8f0;
}
.history li:first-child { border-top: 0; }
.history-main { display: flex; flex-direction: column; min-width: 0; }
.history-main span { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.history-meta { grid-column: 1; display: flex; gap: 10px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.history-meta .amount { color: var(--text); font-weight: 600; }
.history .button { grid-column: 2; grid-row: 1 / span 2; font-size: 14px; padding: 8px 12px; }
.tag { background: #e2e8f0; border-radius: 4px; padding: 0 6px; }

.login { max-width: 360px; padding-top: 12vh; }
.login button { width: 100%; margin-top: 18px; }
