/*
 * Threads Monitor — personal layer.
 *
 * Loaded after public/css/app.css (via resources/views/personal/partials/head-extra.blade.php).
 * Direction: Minimalism / Swiss, monochrome zinc scale, data-dense dashboard rhythm.
 *   - 1. Token overrides (light on :root, dark on [data-theme="dark"]).
 *   - 2. Brand: Threads mark + "Threads Monitor" wordmark with a black/white/grey shimmer.
 *   - 3. Refinements of existing elements and classes (no new markup required, so views
 *        changed by other work pick the style up automatically).
 *   - 4. Responsive and reduced-motion.
 * No external fonts, CDNs or build step.
 */

/* ---- 1. Tokens ------------------------------------------------------------------------- */

:root {
    /* Zinc monochrome. Contrast on --color-bg / --color-surface noted where it matters. */
    --color-bg: #fafafa;
    --color-surface: #ffffff;
    --color-surface-muted: #f4f4f5;
    --color-input-bg: #ffffff;
    --color-text: #09090b;          /* 19.4:1 on bg */
    --color-text-muted: #52525b;    /* 7.4:1 on bg, 7.0:1 on surface-muted */
    --color-border: #e4e4e7;        /* decorative dividers */
    --color-border-strong: #71717a; /* control outlines, 4.6:1 on white (non-text >= 3:1) */
    --color-accent: #18181b;
    --color-accent-hover: #3f3f46;
    --color-on-accent: #fafafa;
    --color-danger: #b91c1c;
    --color-danger-hover: #991b1b;
    --color-on-danger: #ffffff;
    --color-success: #15803d;
    --color-success-bg: #f0fdf4;
    --color-danger-bg: #fef2f2;
    --color-warning: #854d0e;
    --color-warning-bg: #fef9c3;
    --color-focus: #18181b;
    --color-row-hover: #f4f4f5;

    --shadow-card: 0 1px 2px rgba(9, 9, 11, 0.04), 0 1px 3px rgba(9, 9, 11, 0.06);
    --shadow-card-hover: 0 2px 4px rgba(9, 9, 11, 0.05), 0 8px 24px rgba(9, 9, 11, 0.08);
    --shadow-focus: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--color-focus);

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --space-5: 24px;
    --space-6: 32px;

    /* Type scale ~1.2 (minor third) on a 15px base, tabular figures for data. */
    --font-sans: "Inter", "SF Pro Text", system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
    --font-size-xs: 12px;
    --font-size-sm: 13px;
    --font-size-md: 15px;
    --font-size-lg: 18px;
    --font-size-xl: 22px;
    --font-size-2xl: 26px;

    --ease-out: cubic-bezier(0.2, 0, 0, 1);
    --dur-fast: 150ms;
    --dur-base: 200ms;

    --target-min: 44px;

    /* Brand shimmer (light): ink -> graphite -> light-grey glint -> graphite -> ink.
       Lightest stop #7c7c85 on bg #fafafa = 4.0:1, on white = 4.1:1 (large title >= 3:1). */
    --brand-ink: #09090b;
    --brand-mid: #3f3f46;
    --brand-glint: #7c7c85;
}

[data-theme="dark"] {
    --color-bg: #09090b;
    --color-surface: #141416;
    --color-surface-muted: #232327;
    --color-input-bg: #0f0f11;
    --color-text: #fafafa;          /* 19.0:1 on bg */
    --color-text-muted: #a1a1aa;    /* 7.8:1 on bg, 6.2:1 on surface-muted */
    --color-border: #2a2a2f;
    --color-border-strong: #71717a; /* 4.1:1 on surface */
    --color-accent: #fafafa;
    --color-accent-hover: #d4d4d8;
    --color-on-accent: #09090b;
    --color-danger: #f87171;
    --color-danger-hover: #fca5a5;
    --color-on-danger: #1a0505;
    --color-success: #4ade80;
    --color-success-bg: #0d2416;
    --color-danger-bg: #2a1010;
    --color-warning: #facc15;
    --color-warning-bg: #2b2408;
    --color-focus: #fafafa;
    --color-row-hover: #1c1c1f;

    --shadow-card: 0 0 0 1px rgba(255, 255, 255, 0.02), 0 1px 2px rgba(0, 0, 0, 0.6);
    --shadow-card-hover: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 8px 24px rgba(0, 0, 0, 0.6);

    /* Brand shimmer (dark): light grey -> near white -> white glint. Darkest stop #a1a1aa on
       bg #09090b = 7.8:1; the glint is the brightest point. */
    --brand-ink: #a1a1aa;
    --brand-mid: #e4e4e7;
    --brand-glint: #ffffff;
}

/* ---- 2. Brand -------------------------------------------------------------------------- */

.brand { font-size: var(--font-size-xl); letter-spacing: -0.01em; }
.tm-brand-link {
    display: inline-flex;
    align-items: center;
    min-height: var(--target-min);
    border-radius: var(--radius-md);
    text-decoration: none;
}
.tm-brand { display: inline-flex; align-items: center; gap: 10px; }
.tm-brand-mark {
    width: 1.15em;
    height: 1.15em;
    flex: none;
    color: var(--brand-ink);
    animation: tm-glint 3.6s ease-in-out infinite;
}
.tm-brand-text {
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.15;
    color: var(--brand-ink); /* fallback where background-clip:text is unsupported */
    background-image: linear-gradient(100deg,
        var(--brand-ink) 0%,
        var(--brand-mid) 30%,
        var(--brand-glint) 50%,
        var(--brand-mid) 70%,
        var(--brand-ink) 100%);
    background-size: 250% 100%;
    background-position: 100% 50%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: tm-shimmer 3.6s ease-in-out infinite;
}
@supports not ((background-clip: text) or (-webkit-background-clip: text)) {
    .tm-brand-text { -webkit-text-fill-color: currentColor; background: none; }
}
@keyframes tm-shimmer {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
/* The mark picks up a faint sheen as the glint passes the start of the word. */
@keyframes tm-glint {
    0%, 100% { color: var(--brand-ink); }
    50%      { color: var(--brand-mid); }
}

.tm-auth-brand { font-size: var(--font-size-2xl); margin-bottom: var(--space-1); }
.tm-auth-sub { margin: 0 0 var(--space-4); }

/* ---- 3. Refinements -------------------------------------------------------------------- */

html { -webkit-text-size-adjust: 100%; }
body {
    font-size: var(--font-size-md);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}
h1, h2, h3 { letter-spacing: -0.015em; font-weight: 650; }
.title-xl { font-size: var(--font-size-xl); }
.title-lg { font-size: var(--font-size-lg); }

a { text-underline-offset: 3px; text-decoration-thickness: 1px; transition: color var(--dur-fast) var(--ease-out); }
a:hover { text-decoration-thickness: 2px; }

/* Focus: a monochrome two-ring halo (surface gap + ink ring), visible on any background. */
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; border-radius: var(--radius-sm); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, .btn-link:focus-visible, summary:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

/* Layout rhythm */
.wrap { padding: var(--space-5) var(--space-4) var(--space-6); }
header.top {
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-border);
}
header.top.guest { border-bottom: 0; padding-bottom: 0; }

/* Navigation: pill items with 44px targets */
nav.links { gap: var(--space-1) var(--space-1); font-size: 14px; }
nav.links a {
    display: inline-flex;
    align-items: center;
    min-height: var(--target-min);
    padding: 0 var(--space-3);
    border-radius: var(--radius-pill);
    color: var(--color-text-muted);
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
nav.links a:hover { color: var(--color-text); background: var(--color-surface-muted); text-decoration: none; }
nav.links a.on { color: var(--color-text); background: var(--color-surface-muted); font-weight: 600; text-decoration: none; }
nav.links .tm-user { padding: 0 var(--space-2); }
nav.links button { min-height: var(--target-min); padding: 0 var(--space-4); }

.theme-toggle {
    width: var(--target-min);
    height: var(--target-min);
    min-height: var(--target-min);
    border-color: var(--color-border);
    background: var(--color-surface);
    transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.theme-toggle:hover { background: var(--color-surface-muted); border-color: var(--color-border-strong); }
.locale-toggle {
    min-width: var(--target-min);
    height: var(--target-min);
    min-height: var(--target-min);
    border-color: var(--color-border);
    transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
button.locale-toggle { padding: 0 var(--space-3); background: var(--color-surface); color: var(--color-text); }
button.locale-toggle:hover { background: var(--color-surface-muted); border-color: var(--color-border-strong); }

/* Cards */
.card {
    border-color: var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    transition: box-shadow var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.list { gap: var(--space-4); margin-top: var(--space-5); }
.list > article.card:hover { box-shadow: var(--shadow-card-hover); border-color: var(--color-border-strong); }
.section { margin-top: var(--space-5); }
.card h2 { font-size: var(--font-size-lg); }

.post-head { gap: var(--space-2) var(--space-3); align-items: center; }
.post-head > div { display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--space-3); min-width: 0; }
.post-head > div > a { display: inline-flex; align-items: center; min-height: var(--target-min); }
.post-head strong { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.post-head .title-lg { font-size: var(--font-size-lg); }

.meta { gap: var(--space-1) var(--space-5); font-size: var(--font-size-sm); color: var(--color-text-muted); margin-top: var(--space-3); }
.meta > span { color: var(--color-text-muted); }

/* KPI tiles: small caps label over a large tabular figure */
.metrics { grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: var(--space-2); margin-top: var(--space-3); }
.metric {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-3) 10px;
    background: var(--color-surface-muted);
}
.metric .k {
    font-size: var(--font-size-xs);
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}
.metric .v {
    margin-top: 2px;
    font-size: 24px;
    line-height: 1.2;
    font-weight: 650;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--color-text);
}
.metric .v.na { font-size: var(--font-size-sm); font-weight: 400; letter-spacing: 0; color: var(--color-text-muted); padding-top: 6px; }

/* Badges */
.tag {
    display: inline-flex;
    align-items: center;
    font-size: var(--font-size-xs);
    font-weight: 500;
    line-height: 1.5;
    padding: 1px var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
}
.tag.warn { border-color: transparent; background: var(--color-warning-bg); color: var(--color-warning); }
.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--font-size-xs);
    font-weight: 600;
    padding: 3px 10px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.status-done { color: var(--color-success); background: var(--color-success-bg); border-color: transparent; }
.status-failed, .status-gone { color: var(--color-danger); background: var(--color-danger-bg); border-color: transparent; }

/* Forms */
label { font-size: 14px; font-weight: 500; color: var(--color-text); }
input[type=email], input[type=password], input[type=url], input[type=text], input[type=search], input[type=number], input[type=date], input:not([type]), select, textarea {
    width: 100%;
    min-height: var(--target-min);
    padding: 10px var(--space-3);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-input-bg);
    color: var(--color-text);
    font: inherit;
    font-size: 16px; /* no iOS zoom */
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
input:hover, select:hover, textarea:hover { border-color: var(--color-text-muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--color-focus); }
input::placeholder, textarea::placeholder { color: var(--color-text-muted); opacity: 1; }
.check { min-height: var(--target-min); margin-top: var(--space-2); font-weight: 400; cursor: pointer; }
.check input { width: 20px; height: 20px; }

/* Buttons */
button, .btn-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--target-min);
    padding: 0 18px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.2;
    transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out),
        border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
button:hover, .btn-link:hover { background: var(--color-accent-hover); text-decoration: none; }
button:active, .btn-link:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
button.danger:hover { background: var(--color-danger-hover); }
button.ghost { background: transparent; color: var(--color-text); border: 1px solid var(--color-border-strong); }
button.ghost:hover { background: var(--color-surface-muted); }
button.small { min-height: var(--target-min); padding: 0 var(--space-3); font-size: var(--font-size-sm); }
button.theme-toggle { padding: 0; }
button.theme-toggle:hover { background: var(--color-surface-muted); }
.tm-block { width: 100%; }

/* Inline action links (e.g. 編輯 in tables, 回清單) get a 44px hit area */
.actions > a, p > a:only-child { display: inline-flex; align-items: center; min-height: var(--target-min); }
.actions { gap: var(--space-2) var(--space-3); }

/* Flash and errors */
.flash {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-card);
}
.err-box { border-radius: var(--radius-md); background: var(--color-danger-bg); border-color: transparent; padding: var(--space-2) var(--space-3); }
.error { font-weight: 500; }

/* Tables: quiet header, hairline rows, hover row, tabular numerals */
table { font-size: 14px; }
th, td { padding: 10px var(--space-3); border-bottom: 1px solid var(--color-border); }
thead th {
    font-size: var(--font-size-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    background: var(--color-surface-muted);
    border-bottom-color: var(--color-border);
}
thead th:first-child { border-top-left-radius: var(--radius-sm); }
thead th:last-child { border-top-right-radius: var(--radius-sm); }
tbody tr { transition: background-color var(--dur-fast) var(--ease-out); }
tbody tr:hover { background: var(--color-row-hover); }
tbody tr:last-child td { border-bottom: 0; }
td { font-variant-numeric: tabular-nums; }
.scroll-x { border: 1px solid var(--color-border); border-radius: var(--radius-md); }

/* Disclosure (details / summary), for expandable sections */
details {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    margin-top: var(--space-3);
}
details > summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--target-min);
    padding: 0 var(--space-3);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    border-radius: var(--radius-md);
    transition: background-color var(--dur-fast) var(--ease-out);
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
    content: "";
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform var(--dur-base) var(--ease-out);
    flex: none;
}
details[open] > summary::before { transform: rotate(45deg); }
details > summary:hover { background: var(--color-surface-muted); }
details[open] > summary { border-bottom: 1px solid var(--color-border); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
details > :not(summary) { margin-left: var(--space-3); margin-right: var(--space-3); }
details > .scroll-x:last-child, details > table:last-child, details > div:last-child { margin-bottom: var(--space-3); }

/* Chart */
.chart .line { stroke: var(--color-text); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--color-surface); stroke: var(--color-text); stroke-width: 2; }
.chart .grid { stroke: var(--color-border); stroke-dasharray: 3 4; }
.chart .axis { stroke: var(--color-border-strong); }
.chart text { fill: var(--color-text-muted); font-variant-numeric: tabular-nums; }

/* Footer */
.site-footer { padding: var(--space-4); font-size: var(--font-size-xs); letter-spacing: 0.02em; border-top-color: var(--color-border); }
.site-footer a {
    display: inline-flex;
    align-items: center;
    min-height: var(--target-min);
    padding: 0 var(--space-2);
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
}
.site-footer a:hover { color: var(--color-text); text-decoration: underline; }

/* Auth card */
.card.auth { margin-top: 8vh; padding: var(--space-6) var(--space-5); }

/* Group sections, group manager and the per-post edit area (contracts G2-G4) */
.list > details.group-section { margin-top: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-card); }
details.group-section > summary { min-height: 52px; padding: 0 var(--space-4); font-size: var(--font-size-md); letter-spacing: -0.01em; }
details.group-section > summary:hover, details.group-manage > summary:hover { background: var(--color-surface-muted); }
details.group-section[open] > summary { border-bottom: 1px solid var(--color-border); }
details.group-section > .group-body {
    margin: 0;
    padding: var(--space-4);
    background: var(--color-bg);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}
.group-body > article.card:hover { box-shadow: var(--shadow-card-hover); border-color: var(--color-border-strong); }
.group-count { border: 1px solid var(--color-border); color: var(--color-text-muted); font-weight: 600; }

details.group-manage { padding: 0; margin-top: var(--space-5); }
details.group-manage > summary { min-height: 52px; padding: 0 var(--space-4); border-radius: var(--radius-lg); }
details.group-manage[open] > summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
details.group-manage > .group-manage-body { margin: 0; padding: 0 var(--space-4) var(--space-4); }
.group-row { border-top-color: var(--color-border); }
.group-row-actions button.ghost { padding: 0 var(--space-3); }

details.post-edit { border: 1px solid var(--color-border); border-top: 1px solid var(--color-border); }
details.post-edit > summary { padding: 0 var(--space-3); }
details.post-edit[open] > summary { margin-bottom: 0; }
details.post-edit > .meta-form { padding: var(--space-3) 0; }

/* ---- 4. Responsive & motion ------------------------------------------------------------ */

@media (max-width: 560px) {
    .wrap { padding: var(--space-4) var(--space-4) var(--space-5); }
    .brand { font-size: 20px; }
    header.top:not(.guest) { padding-right: 120px; }
    nav.links { margin-left: calc(-1 * var(--space-3)); }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric .v { font-size: 20px; }
    .card.auth { margin-top: 4vh; padding: var(--space-5) var(--space-4); }
    .row button { width: 100%; }
    details.group-section > summary, details.group-manage > summary { padding: 0 var(--space-3); }
    details.group-section > .group-body { padding: var(--space-2); }
    details.group-manage > .group-manage-body { padding: 0 var(--space-3) var(--space-3); }
}

@media (prefers-reduced-motion: reduce) {
    .tm-brand-text, .tm-brand-mark { animation: none; }
    .tm-brand-text { background-position: 50% 50%; }
    *, *::before, *::after { transition-duration: 0.01ms !important; }
    button:active, .btn-link:active { transform: none; }
}
