/* /css/app.css - styles for index.php. Minified to app.min.css on install. */

:root {
    color-scheme: light dark;
    --bg: #f5f7fa;
    --panel: #ffffff;
    --border: #d0d9e2;
    --text: #14202b;
    --muted: #5a6b7c;
    --accent: #0969da;
    --ok: #1a7f37;
    --warn: #9a6700;
    --err: #cf222e;
    --field-bg: #ffffff;
    --inset-bg: rgba(0, 0, 0, .03);
    --titlebar-bg: rgba(9, 105, 218, .10);
    --titlebar-btn-border: #b7cade;
    --btn-hover-bg: rgba(0, 0, 0, .08);

    @media (prefers-color-scheme: dark) {
        --bg: #0b0f14;
        --panel: #131a23;
        --border: #22303f;
        --text: #e6edf5;
        --muted: #8fa3b8;
        --accent: #2f81f7;
        --ok: #3fb950;
        --warn: #d29922;
        --err: #f85149;
        --field-bg: rgba(255, 255, 255, .03);
        --inset-bg: rgba(255, 255, 255, .02);
        --titlebar-bg: rgba(47, 129, 247, .16);
        --titlebar-btn-border: #27405f;
        --btn-hover-bg: rgba(255, 255, 255, .12);
    }
}

* {
    box-sizing: border-box;
}

/* Author display rules (e.g. .icon-btn inline-flex) beat the UA's
   [hidden] { display: none }; this restores it. */
[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

/* Native rubber-band bounce would drag the page under the indicator
   and fight the gesture; PullToRefresh (ts/app.ts) replaces it. */
html {
    overscroll-behavior-y: none;
}

body {
    min-height: 100dvh;
    padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: center;
}

main {
    width: 100%;
    max-width: 560px;
}

.app-header {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    align-content: center;
    gap: 10px;
    margin: 0 0 20px;

    .logo {
        height: 28px;
        width: auto;
    }

    /* line-height 1 keeps the text box tight so centering tracks the
       glyphs, not leading. */
    h1 {
        font-size: 1.5rem;
        line-height: 1;
        margin: 0;
        letter-spacing: -0.01em;
    }

    /* Pinned so it stays flush right while #composeToggle is hidden. */
    #settingsToggle {
        grid-column: 4;
    }
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 16px;
}

/* Spans the card edge to edge: negative margins cancel .card's padding,
   and the top radius is the card's minus its 1px border so the fill sits
   flush inside the rounded corner. Right padding is tighter so a 44px
   button's own box supplies the visual inset. */
.card-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 60px;
    margin: -20px -20px 16px;
    padding: 8px 8px 8px 20px;
    background: var(--titlebar-bg);
    border-bottom: 1px solid var(--border);
    border-radius: 13px 13px 0 0;

    h2 {
        /* Lets the title wrap instead of pushing the confirm pair off a
           narrow screen. */
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 8px;
        margin: 0;
        font-size: 1rem;
        font-weight: 600;
        line-height: 1.2;
    }

    .count-badge {
        min-width: 1.75em;
        padding: 2px 7px;
        border: 1px solid var(--titlebar-btn-border);
        border-radius: 999px;
        background: var(--panel);
        color: var(--muted);
        font-size: 0.75rem;
        font-variant-numeric: tabular-nums;
        text-align: center;
    }

    button.secondary {
        flex: none;
    }

    /* Same contrast against the tinted bar as --border has against --panel. */
    button.secondary,
    .icon-btn {
        border-color: var(--titlebar-btn-border);
    }
}

/* Inline confirmation pair (InlineConfirm) that replaces its trigger
   button in place. */
.confirm-group {
    display: flex;
    gap: 8px;

    &[hidden] {
        display: none;
    }
}

/* Clear and Cancel share a min-width so Cancel lands exactly under the
   tap that hit Clear. Auto margin pins the right-hand item at the end
   regardless of the title's width. */
#clearHistory,
#clearCancel {
    min-width: 88px;
}

#clearHistory,
.card-titlebar > .confirm-group {
    margin-left: auto;
}

/* Full-width trigger: the pair splits its row. */
#disableConfirm button {
    flex: 1;
}

button.secondary.danger {
    color: var(--err);
    border-color: var(--err);
}

.update-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-color: var(--accent);
}

/* Body text of the plain notice cards; the explicit zero bottom margin
   keeps a <p>'s UA margin out of the card. */
#iosHelp ol,
#networkBlocked p {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

#iosHelp ol {
    padding-left: 20px;

    li {
        margin-bottom: 6px;
    }
}

button {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    padding: 15px 18px;
    font-size: 1.05rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: 0;
    border-radius: 12px;
    cursor: pointer;
    transition: opacity .15s ease, background-color .15s ease;

    &:active {
        opacity: .75;
    }

    &[disabled] {
        opacity: .45;
        cursor: not-allowed;
    }

    &.secondary {
        background: transparent;
        color: var(--muted);
        border: 1px solid var(--border);
        font-weight: 500;
        font-size: 0.95rem;
        width: auto;
        min-height: 44px;
        padding: 9px 16px;
        display: inline-flex;
        align-items: center;
        justify-content: center;

        /* Outlined buttons only (the filled accent button has its own
           color); .icon-btn repeats this. any-hover, not hover: a
           touchscreen PC reports touch as its primary pointer, so
           (hover: hover) never matches there despite a mouse. Phones have
           no hovering pointer at all, so a tap leaves no fill stuck. */
        @media (any-hover: hover) {
            &:not([disabled]):hover {
                background: var(--btn-hover-bg);
            }
        }
    }
}

/* Destructive: stops all pushes to this device. */
#disable {
    width: 100%;
    color: var(--err);
}

/* 44x44: Apple HIG minimum touch target. */
.icon-btn {
    flex: none;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;

    @media (any-hover: hover) {
        &:not([disabled]):hover {
            background: var(--btn-hover-bg);
        }
    }

    svg {
        width: 22px;
        height: 22px;
        fill: currentColor;
    }
}

.field-label {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 6px;
}

input[type="text"],
select,
textarea {
    display: block;
    width: 100%;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: var(--field-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 14px;
    -webkit-appearance: none;
    appearance: none;

    &::placeholder {
        color: var(--muted);
        font-style: italic;
    }

    &:focus {
        outline: none;
        border-color: var(--accent);
    }
}

textarea {
    resize: vertical;
    min-height: 88px;
}

/* The native option list can't use the select's translucent --field-bg and
   falls back to white, under options that inherit the light dark-mode
   text. Solid colors from the same theme keep the two in step. */
select option {
    background: var(--panel);
    color: var(--text);
}

/* Flex stretch gives input and button equal height without pixel matching. */
.input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;

    input[type="text"] {
        flex: 1;
        margin-bottom: 0;
    }
}

#status,
#composeStatus {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--inset-bg);
    font-size: 0.92rem;
    white-space: pre-wrap;
    word-break: break-word;
    display: none;

    &.show {
        display: block;
    }

    &.ok {
        border-color: var(--ok);
        color: var(--ok);
    }

    &.warn {
        border-color: var(--warn);
        color: var(--warn);
    }

    &.err {
        border-color: var(--err);
        color: var(--err);
    }
}

.meta {
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 14px;
    word-break: break-all;

    code {
        color: var(--text);
        font-size: 0.8rem;
    }
}

.empty-hint {
    color: var(--muted);
    font-size: 0.9rem;
}

.history-item {
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;

    &:last-child {
        margin-bottom: 0;
    }

    /* Only items with a real target are tappable (historyTargetUrl()). */
    &.has-url {
        cursor: pointer;
    }

    /* Stripe strength tracks urgency; very-low keeps the plain --border. */
    &.urgency-high {
        border-left-color: var(--err);
    }

    &.urgency-normal {
        border-left-color: var(--accent);
    }

    &.urgency-low {
        border-left-color: var(--muted);
    }

    .history-item-top {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 10px;
    }

    .history-title {
        font-weight: 600;
        margin: 0 0 4px;
    }

    .history-body {
        color: var(--muted);
        font-size: 0.92rem;
        margin: 0;
        white-space: pre-wrap;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .history-time {
        color: var(--muted);
        font-size: 0.78rem;
        margin-top: 6px;

        /* Reply link: undoes the global full-width, filled button so it
           reads as inline text. Vertical padding with a matching negative
           margin enlarges the tap area without moving the line. */
        .sender-link {
            width: auto;
            padding: 6px 2px;
            margin: -6px 0;
            background: none;
            border: 0;
            border-radius: 4px;
            color: var(--accent);
            font: inherit;
            text-decoration: underline;
            text-underline-offset: 2px;
        }
    }

    .history-url {
        color: var(--accent);
        font-size: 0.78rem;
        margin-top: 2px;
        word-break: break-all;
    }

    .history-actions {
        display: flex;
        gap: 8px;
        flex: none;
    }
}

.target-list {
    margin-bottom: 14px;
}

/* The label is the tap target, so it carries the 44px minimum. */
.target-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    min-height: 44px;
    font-size: 0.95rem;

    input {
        width: 20px;
        height: 20px;
        margin: 0;
        flex: none;
    }
}

/* Clipped, not display:none, so it stays in constraint validation
   (see updateTargetsValidity()). */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --pull (px) and --pull-progress (0..1) are driven from PullToRefresh;
   transitions are suppressed while dragging so the indicator tracks the
   finger 1:1 and only animates on release. */
.pull-indicator {
    position: fixed;
    top: env(safe-area-inset-top);
    left: 50%;
    z-index: 10;
    width: 56px;
    height: 56px;
    margin-left: -28px;
    border-radius: 50%;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--muted);
    display: grid;
    place-items: center;
    pointer-events: none;
    opacity: var(--pull-progress, 0);
    transform: translateY(calc(var(--pull, 0px) - 100%));
    transition: transform .2s ease, opacity .2s ease, color .15s ease;

    svg {
        width: 34px;
        height: 34px;
        transform: rotate(calc(var(--pull-progress, 0) * 270deg));
        transition: transform .2s ease;
    }

    &.dragging {
        transition: none;

        svg {
            transition: none;
        }
    }

    &.armed {
        color: var(--accent);
    }

    &.refreshing svg {
        animation: pull-spin .8s linear infinite;
    }
}

@keyframes pull-spin {
    to {
        transform: rotate(360deg);
    }
}
