/* ============================================================
   PhibunTime — design system
   ธีม "สมุดลงเวลา + ตราประทับ" : กระดาษครีม / หมึกเขียวเข้ม /
   ตราประทับแดงชาด — Chonburi (display) + Anuphan (body) + IBM Plex Mono (ตัวเลข)
   ============================================================ */

:root {
    --paper:      #f2ecdd;
    --paper-hi:   #faf6ea;
    --paper-lo:   #e9e1cc;
    --ink:        #16382b;
    --ink-soft:   #43604f;
    --ink-faint:  #7c927f;
    --line:       #d8cdb2;
    --stamp:      #c03d1d;
    --stamp-hi:   #e2582c;
    --go:         #1c7a4c;
    --go-hi:      #26996159;
    --gold:       #b98a2f;
    --danger:     #b3261e;
    --radius-lg:  22px;
    --radius-md:  14px;
    --shadow-card: 0 2px 0 rgba(22,56,43,.08), 0 14px 34px -18px rgba(22,56,43,.35);
    --font-display: 'Chonburi', serif;
    --font-body: 'Anuphan', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.55;
    /* กระดาษสมุดบัญชี: grain + เส้นบรรทัดจาง ๆ */
    background-image:
        repeating-linear-gradient(0deg, transparent 0 34px, rgba(22,56,43,.045) 34px 35px),
        radial-gradient(ellipse 120% 90% at 50% -10%, rgba(255,252,240,.9), transparent 55%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.2 0 0 0 0 0.15 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: rgba(226,88,44,.25); }

/* ── Top bar ── */
.topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 18px 10px;
    max-width: 1060px; margin: 0 auto;
}
.seal {
    width: 46px; height: 46px; flex: none;
    border: 2.5px solid var(--ink); border-radius: 50%;
    display: grid; place-items: center;
    font-family: var(--font-display); font-size: 21px; color: var(--ink);
    position: relative; background: var(--paper-hi);
    box-shadow: inset 0 0 0 3px var(--paper-hi), inset 0 0 0 4.5px var(--ink);
}
.brand h1 {
    font-family: var(--font-display); font-weight: 400;
    font-size: 22px; line-height: 1.1; letter-spacing: .3px;
}
.brand small { display: block; font-size: 11.5px; color: var(--ink-soft); letter-spacing: .2px; }
.topbar .spacer { flex: 1; }

.top-user { text-align: right; font-size: 12.5px; color: var(--ink-soft); line-height: 1.3; }
.top-user b { display: block; font-size: 13.5px; color: var(--ink); font-weight: 600; }
.linklike {
    background: none; border: none; color: var(--stamp); font-family: var(--font-body);
    font-size: 12px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; padding: 0;
}

/* ── Layout ── */
.wrap { max-width: 1060px; margin: 0 auto; padding: 6px 16px 60px; }

/* ── Cards ── */
.card {
    background: var(--paper-hi);
    border: 1.5px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 20px;
    position: relative;
}
.card + .card { margin-top: 16px; }
.card-title {
    font-family: var(--font-display); font-weight: 400; font-size: 17px;
    display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
}
.card-title::after { content: ''; flex: 1; border-top: 1.5px dashed var(--line); }

/* ── Buttons ── */
.btn {
    font-family: var(--font-body); font-weight: 600; font-size: 15px;
    border-radius: var(--radius-md); border: 1.5px solid var(--ink);
    background: var(--ink); color: var(--paper-hi);
    padding: 12px 22px; cursor: pointer;
    transition: transform .08s ease, box-shadow .15s ease, opacity .15s;
    box-shadow: 0 3px 0 rgba(22,56,43,.35);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(22,56,43,.35); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn-ghost {
    background: transparent; color: var(--ink);
    border: 1.5px solid var(--ink); box-shadow: none;
}
.btn-stamp { background: var(--stamp); border-color: var(--stamp); box-shadow: 0 3px 0 rgba(146,42,17,.5); }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 10px; }

/* ── Inputs ── */
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 5px; }
.field input, .field select {
    width: 100%; font-family: var(--font-body); font-size: 15px; color: var(--ink);
    background: #fffdf6; border: 1.5px solid var(--line); border-radius: var(--radius-md);
    padding: 11px 14px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
    border-color: var(--ink-soft); box-shadow: 0 0 0 3px rgba(28,122,76,.15);
}

/* ── Chips / badges ── */
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12.5px; font-weight: 600;
    border-radius: 999px; padding: 5px 12px;
    border: 1.5px solid currentColor;
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip.ok    { color: var(--go); background: rgba(28,122,76,.08); }
.chip.warn  { color: var(--gold); background: rgba(185,138,47,.1); }
.chip.bad   { color: var(--danger); background: rgba(179,38,30,.07); }
.chip.idle  { color: var(--ink-faint); background: rgba(124,146,127,.1); }
.chip.ok .chip-dot { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(28,122,76,.18); } }

/* ── ตราประทับ (imprint) ── */
.stamp-imprint {
    display: inline-block;
    font-family: var(--font-display);
    color: var(--stamp);
    border: 3px double var(--stamp);
    border-radius: 10px;
    padding: 4px 14px;
    transform: rotate(-6deg);
    letter-spacing: 1px;
    text-transform: uppercase;
    mix-blend-mode: multiply;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .9 .12'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23g)'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .9 .12'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23g)'/%3E%3C/svg%3E");
}
.stamp-imprint.green { color: var(--go); border-color: var(--go); }

/* ── Toast ── */
#toast {
    position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
    background: var(--ink); color: var(--paper-hi);
    font-size: 14px; font-weight: 500;
    padding: 12px 20px; border-radius: 12px;
    box-shadow: 0 10px 30px -8px rgba(22,56,43,.5);
    opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
    max-width: min(92vw, 480px); text-align: center; z-index: 3000;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* ── Modal ── */
.modal-back {
    position: fixed; inset: 0; background: rgba(22,56,43,.45);
    backdrop-filter: blur(3px);
    display: none; align-items: flex-end; justify-content: center; z-index: 2000;
    padding: 16px;
}
.modal-back.show { display: flex; animation: fadeIn .2s ease; }
.modal {
    background: var(--paper-hi); border-radius: var(--radius-lg);
    border: 1.5px solid var(--line);
    width: min(440px, 100%); padding: 22px;
    animation: slideUp .25s cubic-bezier(.2,.9,.3,1.2);
    max-height: 88vh; overflow: auto;
}
@media (min-width: 640px) { .modal-back { align-items: center; } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } }

/* ── Tables ── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
    text-align: left; font-size: 11.5px; letter-spacing: .4px; color: var(--ink-faint);
    font-weight: 600; text-transform: uppercase;
    padding: 8px 10px; border-bottom: 2px solid var(--line);
}
.tbl td { padding: 9px 10px; border-bottom: 1px dashed var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.mono { font-family: var(--font-mono); font-weight: 500; }

.muted { color: var(--ink-faint); }
.hidden { display: none !important; }
