:root {
    --ink: #17233b;
    --ink-soft: #44506a;
    --muted: #6b7488;
    --line: #ddd6c8;
    --paper: #f6f2ea;
    --surface: #fffdf9;
    --gold: #b08a45;
    --gold-soft: #f0e3c8;
    --navy: #16243d;
    --danger: #a33a35;
    --ok: #2c6b4f;
    --radius: 14px;
    --shadow: 0 12px 30px rgba(23, 35, 59, .08);
    --font: "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background:
        radial-gradient(900px 400px at 15% -10%, #efe6d5 0%, transparent 60%),
        radial-gradient(700px 380px at 100% 0%, #e6ecf3 0%, transparent 55%),
        var(--paper);
    min-height: 100vh;
}
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; line-height: 1.22; margin: 0; }
p { margin: 0 0 10px; }
a { color: var(--navy); }

.appbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px clamp(14px, 3vw, 28px);
    background: rgba(255, 253, 249, .94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px;
    display: grid; place-items: center; flex: 0 0 auto;
    background: var(--navy); color: var(--gold-soft);
    font-weight: 700; letter-spacing: .5px; font-size: 13px;
}
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 11.5px; letter-spacing: .2px; }
.appbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.userchip {
    max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--ink-soft); font-size: 13px;
}
.inline-form { margin: 0; }

.page {
    width: min(1040px, calc(100% - 28px));
    margin: 22px auto 48px;
    display: grid;
    gap: 18px;
}
.hero {
    padding: clamp(18px, 4vw, 30px);
    border-radius: 18px;
    color: #f7f2e7;
    background:
        linear-gradient(115deg, rgba(176, 138, 69, .22), transparent 52%),
        linear-gradient(160deg, #1b2a45, #101b30);
    box-shadow: var(--shadow);
}
.hero h1 { font-size: clamp(26px, 4vw, 36px); margin-bottom: 10px; }
.hero p { color: #d9dced; max-width: 780px; margin-bottom: 14px; }
.disclaimer {
    display: inline-block;
    padding: 7px 12px;
    border: 1px solid rgba(240, 227, 200, .4);
    border-radius: 999px;
    background: rgba(240, 227, 200, .1);
    color: #f3e5c6;
    font-size: 12.5px;
    letter-spacing: .2px;
}
.meter { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 14px; font-size: 12.5px; color: #bfc6d8; }
.meter strong { color: #f3e5c6; }
.privacy-note { margin: 10px 0 0; font-size: 12px; color: #e7cf9f; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(16px, 3vw, 24px);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head h2 { font-size: 20px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; }
.input {
    width: 100%;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 12px 13px;
    resize: vertical;
}
.input:focus { outline: 2px solid rgba(176, 138, 69, .35); border-color: var(--gold); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 14px; }
.chip {
    font: inherit; font-size: 12.5px; line-height: 1;
    padding: 8px 11px;
    color: var(--ink-soft);
    background: #faf7f0;
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
}
.chip:hover { border-color: var(--gold); color: var(--ink); }

.submit-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.counter { margin-left: auto; color: var(--muted); font-size: 12px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    font: inherit; font-size: 14px; font-weight: 600;
    padding: 11px 18px;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:focus-visible, .modal-x:focus-visible { outline: 2px solid rgba(176, 138, 69, .65); outline-offset: 2px; }
.btn-primary { background: var(--navy); color: #f7f2e7; }
.btn-primary:hover:not(:disabled) { background: #213459; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--gold); }
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.pill-on { background: #e5f1ea; color: var(--ok); }
.pill-off { background: #f7e6e3; color: var(--danger); }
.pill-warn { background: var(--gold-soft); color: #7a5a1f; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.alert { border-radius: 11px; padding: 12px 14px; font-size: 14px; margin: 12px 0 0; }
.alert p { margin: 5px 0 0; }
.alert-error { background: #fbecea; border: 1px solid #ecc9c5; color: #7f2b26; }
.alert-warn { background: #fdf5e4; border: 1px solid #ead8b0; color: #74551d; }

.status-panel { border-color: #cbd8e8; background: #f6f9fd; }
.status-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 4px rgba(176, 138, 69, .18); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.75); opacity: .55; } }
.progress { height: 5px; border-radius: 99px; background: #e4eaf3; margin: 12px 0 8px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 5%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), #d6b06a); transition: width .8s ease; }

.result { display: grid; gap: 14px; }
.result-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.memo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.memo-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.memo-block h3 { font-size: 17px; margin-bottom: 8px; }
.memo-block ul { margin: 0; padding-left: 20px; }
.memo-block li { margin: 4px 0; }
.claim { border-left: 3px solid var(--gold); padding: 2px 0 2px 12px; margin: 10px 0; }
.claim:first-child { margin-top: 0; }
.claim-text { margin: 0 0 7px; }
.cite-row { display: flex; flex-wrap: wrap; gap: 6px; }
.cite-chip {
    display: inline-block;
    font-size: 11.5px;
    padding: 4px 8px;
    border-radius: 7px;
    background: #eef2f8;
    color: #263a5c;
    border: 1px solid #d5deeb;
    cursor: pointer;
}
.cite-chip:hover { background: #e3eaf4; }

.src { border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; margin: 8px 0; background: #fff; }
.src summary { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; cursor: pointer; list-style: none; }
.src summary::-webkit-details-marker { display: none; }
.src-main { min-width: 0; display: grid; gap: 2px; }
.src-main strong { font-size: 13px; color: var(--navy); overflow-wrap: anywhere; }
.src-title { font-size: 12.5px; color: var(--ink-soft); }
.src-score { flex: 0 0 auto; font-size: 11px; color: var(--muted); }
.src-text { margin: 10px 0 6px; font-size: 13.5px; color: #2a3346; white-space: pre-wrap; overflow-wrap: anywhere; }
.src.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%,100% { background: #fff; } 30% { background: #fdf3dd; } }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history-btn {
    width: 100%; text-align: left; font: inherit; color: inherit;
    background: #fbf9f4; border: 1px solid var(--line); border-radius: 11px;
    padding: 11px 13px; cursor: pointer; display: grid; gap: 5px;
}
.history-btn:hover { border-color: var(--gold); }
.history-q { font-size: 13.5px; }
.history-meta { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.badge { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; padding: 2px 7px; border-radius: 99px; }
.badge-done { background: #e5f1ea; color: var(--ok); }
.badge-queued, .badge-running { background: #fdf1da; color: #7a5a1f; }
.badge-error, .badge-rejected { background: #fbecea; color: var(--danger); }

.foot { color: var(--muted); font-size: 12px; padding: 6px 2px; }
.foot p { margin: 3px 0; }

.hero-link { color: #f3e5c6; text-decoration: underline; text-underline-offset: 2px; }
.month-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.month-form label { font-size: 12px; color: var(--muted); }
.input-month { width: auto; min-width: 150px; padding: 8px 10px; }
.usage-table-wrap { overflow-x: auto; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.usage-table th, .usage-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.usage-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 700; }
.usage-table td.num { text-align: right; white-space: nowrap; }
.usage-table tr.is-over td { background: #fdf0ee; }
.usage-user strong { display: block; }
.usage-user small { display: block; color: var(--muted); font-size: 11.5px; }
.usage-bar { height: 6px; min-width: 90px; border-radius: 99px; background: #eee7d8; overflow: hidden; margin-bottom: 4px; }
.usage-bar > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), #d6b06a); }

/* Logout confirmation */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16, 20, 30, .45);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 100;
    padding: 20px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 20px;
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    overflow-y: auto;
    overflow-x: clip;
    box-shadow: var(--shadow);
    margin: auto;
}
.modal-logout { max-width: 420px; }
.modal-head {
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-x {
    background: none;
    border: 0;
    padding: 0 2px;
    font: inherit;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
}
.modal-body { padding: 24px; }
.modal-foot {
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.logout-body { text-align: center; padding: 28px 30px; }
.logout-ico {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, var(--navy), #2b3f63);
    color: #f3e5c6;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 22px rgba(23, 35, 59, .28);
}
.logout-ico svg { width: 28px; height: 28px; }
.logout-title {
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--ink);
}
.logout-sub {
    color: var(--muted);
    font-size: .86rem;
    margin-top: 6px;
    line-height: 1.7;
}
.logout-foot { justify-content: center; gap: 10px; }
.btn-logout { background: var(--danger); color: #fff; }
.btn-logout:hover:not(:disabled) { background: #8f312d; color: #fff; }
.btn svg { width: 14px; height: 14px; flex: 0 0 auto; }
body.modal-open { overflow: hidden; }

/* Login */
.login-body {
    display: grid; place-items: center;
    min-height: 100vh;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.login-wrap { width: min(430px, 100%); }
.login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: clamp(22px, 5vw, 34px);
}
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 1.1px; text-transform: uppercase; color: var(--gold); margin-bottom: 6px; }
.login-card h1 { font-size: 30px; margin-bottom: 8px; }
.login-sub { color: var(--ink-soft); font-size: 13.5px; margin-bottom: 18px; }
.login-note { margin: 18px 0 0; color: var(--muted); font-size: 11.5px; border-top: 1px solid var(--line); padding-top: 12px; }

@media (max-width: 640px) {
    body { font-size: 14.5px; }
    .page { width: calc(100% - 20px); margin-top: 14px; gap: 14px; }
    .appbar { padding: 10px 12px; }
    .brand small { display: none; }
    .userchip { display: none; }
    .meter { display: grid; }
    .memo-grid { grid-template-columns: 1fr; }
    .input, .login-card .input { font-size: 16px; }
    .btn { padding: 12px 16px; }
    .submit-row .btn-primary { width: 100%; }
    .counter { margin-left: 0; }
    .src summary { flex-wrap: wrap; }
    .src-score { margin-left: 0; }
    .hero { border-radius: 14px; }
    .panel, .memo-block { padding: 15px; }
}
@media (max-width: 640px) {
    .admin-link { display: none; }
    .month-form { width: 100%; }
    .input-month { flex: 1 1 auto; }
    .usage-table thead { display: none; }
    .usage-table, .usage-table tbody, .usage-table tr, .usage-table td { display: block; width: 100%; }
    .usage-table tr { border: 1px solid var(--line); border-radius: 11px; margin: 0 0 8px; padding: 8px 10px; background: #fbf9f4; }
    .usage-table td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; text-align: right; }
    .usage-table td::before { content: attr(data-label); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; font-weight: 700; text-align: left; }
    .usage-table td.num { white-space: normal; }
    .usage-table td.usage-user { display: block; text-align: left; }
    .usage-table td.usage-user::before { display: block; margin-bottom: 4px; }
    .usage-bar { margin-top: 4px; }
    .modal-backdrop { padding: 12px; align-items: center; }
    .modal-head { padding: 16px 18px; }
    .modal-body { padding: 20px 18px; }
    .modal-foot { padding: 14px 18px; flex-wrap: wrap; }
    .logout-foot .btn { flex: 1 1 0; }
    .logout-body { padding: 24px 18px; }
}
@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
