/* ============================================================
   Drafts Web Capture — 2026 design
   System colors · CSS custom properties · Layered shadows
   ============================================================ */

:root {
    --blue:       #173973;
    --blue-dim:   rgba(23, 57, 115, 0.11);
    --blue-hover: #1e4a8a;
    --orange:     #c07000;
    --orange-dim: rgba(192, 112, 0, 0.10);
    --ink:        #1c1c1e;
    --ink-2:      #3a3a3c;
    --ink-3:      #636366;
    --ink-4:      #8e8e93;
    --ink-5:      #aeaeb2;
    --ink-6:      #c7c7cc;
    --divider:    #e5e5ea;
    --bg:         #F0F0F2;
    --surface:    #ffffff;
    --surface-2:  #f9f9fb;
    --radius-sm:  8px;
    --radius:     13px;
    --radius-lg:  16px;
    --shadow-card:
        0 0 0 0.5px rgba(0,0,0,0.08),
        0 2px 6px  rgba(0,0,0,0.05),
        0 8px 24px rgba(0,0,0,0.04);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html { -webkit-font-smoothing: antialiased; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text',
                 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.5;
}

/* ── Page layout ─────────────────────────────────────────── */

.page-wrapper {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px 72px;
}

/* ── Header ──────────────────────────────────────────────── */

.site-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 0 14px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    color: inherit;
}

.logo-icon { flex-shrink: 0; }

.logo-brand {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.025em;
}

.logo-suffix {
    font-size: 1rem;
    font-weight: 400;
    color: var(--blue);
    letter-spacing: -0.01em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}


.btn-send-all,
.btn-clear-all-tabs {
    background: var(--blue);
    border: none;
    color: #fff;
    padding: 5px 13px;
    border-radius: 7px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.12s;
    box-shadow: 0 1px 3px rgba(23,57,115,.25);
}
.btn-send-all:hover:not(:disabled),
.btn-clear-all-tabs:hover:not(:disabled) { background: var(--blue-hover); }

.btn-send-all:disabled,
.btn-clear-all-tabs:disabled {
    opacity: 0.35;
    cursor: default;
    pointer-events: none;
}

.btn-clear-all-tabs {
    background: var(--surface-2);
    color: var(--ink-3);
    border: 1px solid var(--divider);
    box-shadow: none;
}
.btn-clear-all-tabs:hover:not(:disabled) {
    background: rgba(0,0,0,0.04);
    color: var(--ink-2);
    border-color: var(--ink-5);
}

/* Two-click confirmation state */
.btn-clear-all-tabs.btn-confirm-danger {
    background: rgba(255,59,48,0.1);
    color: #ff3b30;
    border-color: rgba(255,59,48,0.3);
}
.btn-clear-all-tabs.btn-confirm-danger:hover {
    background: rgba(255,59,48,0.18);
    border-color: rgba(255,59,48,0.5);
}

/* ── Alerts ──────────────────────────────────────────────── */

#alert-container { margin-bottom: 10px; }

.alert {
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: 0.84rem;
    line-height: 1.45;
}
.alert.success { background: rgba(52,199,89,.1);   color: #1a5c2a; border: 1px solid rgba(52,199,89,.22); }
.alert.error   { background: rgba(255,59,48,.07);  color: #7a1a1a; border: 1px solid rgba(255,59,48,.18); }
.alert.warning { background: rgba(255,149,0,.07);  color: #6b4000; border: 1px solid rgba(255,149,0,.18); }
.alert.info    { background: rgba(0,122,255,.07);  color: #1a3a7a; border: 1px solid rgba(0,122,255,.16); }
.alert a { color: inherit; font-weight: 600; }

/* ── Card base ───────────────────────────────────────────── */

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    margin-bottom: 12px;
    overflow: hidden;
}

/* ── Sign-in card ────────────────────────────────────────── */

.sign-in-card {
    padding: 56px 40px 48px;
    text-align: center;
}

.sign-in-icon {
    margin: 0 auto 20px;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sign-in-icon img {
    width: 56px;
    height: 56px;
    border-radius: 13px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12), 0 0 0 0.5px rgba(0,0,0,0.08);
}

.sign-in-title {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.025em;
    margin-bottom: 10px;
}

.sign-in-description {
    font-size: 0.9rem;
    color: var(--ink-3);
    line-height: 1.65;
    margin-bottom: 32px;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.btn-use-local {
    background: none;
    border: 1px solid var(--divider);
    color: var(--ink-3);
    padding: 8px 22px;
    border-radius: var(--radius-sm);
    font-size: 0.84rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.btn-use-local:hover {
    border-color: var(--ink-5);
    color: var(--ink-2);
    background: var(--surface-2);
}

/* ── Capture card ────────────────────────────────────────── */

.capture-card { padding: 0; }

/* ── Tab bar ─────────────────────────────────────────────── */

.tab-bar {
    display: flex;
    align-items: stretch;
    background: var(--surface-2);
    border-bottom: 1px solid var(--divider);
    min-height: 34px;
    position: relative;
}

/* Scrollable tab container — takes all space, + button pinned outside */
.tab-scroll {
    display: flex;
    align-items: stretch;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
    padding: 0 4px 0 0;
    cursor: default;
    user-select: none;
}
.tab-scroll::-webkit-scrollbar { display: none; }
.tab-scroll.dragging { cursor: grabbing; }

.tab-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    border: none;
    background: transparent;
    color: var(--ink-4);
    font-size: 0.77rem;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.1s, border-color 0.1s, background 0.1s;
    /* Elastic: grow to fill when few tabs, compress then scroll when many */
    flex: 1 1 0;
    min-width: 72px;
    max-width: 180px;
}
.tab-item:hover { color: var(--ink-2); background: rgba(0,0,0,0.03); }
.tab-item.active {
    color: var(--ink);
    font-weight: 600;
    border-bottom-color: var(--blue);
}

/* Fade indicator for tabs with local-only content */
.tab-item.local-only { opacity: 0.55; }
.tab-item.local-only:hover,
.tab-item.local-only.active { opacity: 1; }

.tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: inherit;
    flex: 1;
    min-width: 0;
}

.tab-close {
    width: 14px;
    height: 14px;
    border: none;
    background: transparent;
    color: var(--ink-5);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    transition: background 0.1s, color 0.1s;
}
.tab-close:hover { background: rgba(0,0,0,0.08); color: var(--ink-2); }

/* Pinned + button — always visible at right edge */
.tab-new-btn {
    flex-shrink: 0;
    border: none;
    border-left: 1px solid var(--divider);
    background: var(--surface-2);
    color: var(--ink-4);
    font-size: 18px;
    line-height: 1;
    padding: 0 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: color 0.1s, background 0.1s;
    position: sticky;
    right: 0;
    z-index: 1;
}
.tab-new-btn:hover {
    color: var(--blue);
    background: var(--surface);
}

/* ── Editor header (Write / Preview toggle) ──────────────── */

.editor-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 16px 0;
}

.editor-toggle {
    display: flex;
    border: 1px solid var(--divider);
    border-radius: 7px;
    overflow: hidden;
}

.view-btn {
    background: var(--surface-2);
    border: none;
    color: var(--ink-3);
    padding: 3px 10px;
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.view-btn + .view-btn { border-left: 1px solid var(--divider); }
.view-btn:hover:not(.active) { background: rgba(0,0,0,0.05); }
.view-btn.active {
    background: var(--blue-dim);
    color: var(--blue);
    font-weight: 600;
}

/* Content textarea — hero of the form */
.content-field {
    border-bottom: 1px solid var(--divider);
}

#draft-content {
    display: block;
    width: 100%;
    padding: 12px 22px 16px;
    border: none;
    outline: none;
    resize: none;
    font-size: 0.96rem;
    font-family: inherit;
    color: var(--ink);
    background: transparent;
    line-height: 1.65;
    min-height: 260px;
    overflow: hidden; /* height managed by pretext */
}

#draft-content::placeholder {
    color: var(--ink-6);
    font-weight: 400;
}

/* ── Markdown preview pane ───────────────────────────────── */

.preview-pane {
    padding: 12px 22px 16px;
    min-height: 260px;
    font-size: 0.96rem;
    line-height: 1.7;
    color: var(--ink);
    overflow-wrap: break-word;
}
.preview-pane h1, .preview-pane h2, .preview-pane h3,
.preview-pane h4, .preview-pane h5, .preview-pane h6 {
    font-weight: 600; letter-spacing: -0.02em; margin: 1em 0 0.35em;
}
.preview-pane h1 { font-size: 1.4em; }
.preview-pane h2 { font-size: 1.15em; }
.preview-pane h3 { font-size: 1em; }
.preview-pane p  { margin: 0.55em 0; }
.preview-pane code {
    background: var(--surface-2);
    border: 1px solid var(--divider);
    border-radius: 4px;
    padding: 0.1em 0.35em;
    font-family: 'SF Mono', Menlo, monospace;
    font-size: 0.87em;
}
.preview-pane pre {
    background: var(--surface-2);
    border: 1px solid var(--divider);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 0.8em 0;
}
.preview-pane pre code { background: none; border: none; padding: 0; }
.preview-pane blockquote {
    border-left: 3px solid var(--blue);
    padding-left: 14px;
    color: var(--ink-3);
    margin: 0.55em 0;
}
.preview-pane ul, .preview-pane ol { padding-left: 1.5em; margin: 0.4em 0; }
.preview-pane li { margin: 0.2em 0; }
.preview-pane a { color: var(--blue); text-decoration: none; }
.preview-pane a:hover { text-decoration: underline; }
.preview-pane hr { border: none; border-top: 1px solid var(--divider); margin: 1.2em 0; }
.preview-pane strong { font-weight: 600; }
.preview-pane em { font-style: italic; }
.preview-empty { color: var(--ink-5); }
.preview-plain {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: inherit;
    color: var(--ink);
    margin: 0;
}
.preview-pane table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.8em 0;
    font-size: 0.92em;
}
.preview-pane th,
.preview-pane td {
    border: 1px solid var(--divider);
    padding: 6px 12px;
    text-align: left;
}
.preview-pane th {
    background: var(--surface-2);
    font-weight: 600;
}
.preview-pane tr:nth-child(even) td { background: var(--surface-2); }

/* Meta bar — tags, syntax, flags, buttons */
.form-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px 10px 16px;
    background: var(--surface-2);
    flex-wrap: wrap;
}

.meta-left {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
    flex: 1;
    min-width: 0;
}

.meta-right {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-shrink: 0;
}

/* Individual meta fields */
.meta-field {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--ink-4);
}

.meta-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

/* Divider between adjacent meta fields */
.meta-left > .meta-field + .meta-field::before {
    content: '';
    display: block;
    width: 1px;
    height: 14px;
    background: var(--divider);
    margin-right: 4px;
    flex-shrink: 0;
}

/* No divider on fields marked .no-divider (flag, location, attach) */
.meta-left > .no-divider::before {
    display: none !important;
}

/* Tags chip area */
.tags-field {
    flex: 1 1 0;
    min-width: 60px;
    max-width: 200px;
    gap: 3px;
    overflow: hidden;
    position: relative;
}

/* Fade-right affordance when chips are present */
.tags-field.has-tags::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 18px;
    background: linear-gradient(to right, transparent, var(--surface-2));
    pointer-events: none;
}

.tags-area {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 3px;
    flex: 1;
    min-width: 0;
}
.tags-area::-webkit-scrollbar { display: none; }

#tags-input {
    flex: 1;
    min-width: 60px;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.82rem;
    font-family: inherit;
    color: var(--ink-2);
    padding: 0;
}
#tags-input::placeholder { color: var(--ink-5); }

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    background: var(--blue-dim);
    color: var(--blue);
    border-radius: 20px;
    padding: 1px 3px 1px 7px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.5;
}

.tag-chip-remove {
    width: 15px;
    height: 15px;
    border: none;
    background: transparent;
    color: var(--blue);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    padding: 0;
    opacity: 0.55;
    transition: opacity 0.1s, background 0.1s;
}
.tag-chip-remove:hover { opacity: 1; background: rgba(23,57,115,0.15); }

/* Syntax select */
#draft-syntax {
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.82rem;
    font-family: inherit;
    color: var(--ink-3);
    cursor: pointer;
    padding: 0;
    -webkit-appearance: auto;
    appearance: auto;
}

/* Flagged checkbox label */
.flagged-field,
.location-field,
.attach-field {
    cursor: pointer;
    user-select: none;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.12s, color 0.12s;
    font-size: 0.82rem;
    gap: 4px;
}
.flagged-field:hover,
.location-field:hover,
.attach-field:hover {
    background: rgba(0,0,0,0.05);
    color: var(--ink-2);
}
.flagged-field input,
.location-field input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0; height: 0;
}

/* Flag checked = orange */
.flagged-field:has(input:checked) {
    background: var(--orange-dim);
    color: var(--orange);
}

/* Location checked = blue */
.location-field:has(input:checked) {
    background: var(--blue-dim);
    color: var(--blue);
}

/* Attach field active state */
.attach-field.has-files {
    background: var(--blue-dim);
    color: var(--blue);
}

/* Action buttons */
.btn-clear {
    background: var(--surface-2);
    border: 1px solid var(--divider);
    color: var(--ink-3);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.btn-clear:hover {
    border-color: var(--ink-5);
    color: var(--ink-2);
    background: rgba(0,0,0,0.03);
}

.btn-create {
    background: var(--blue);
    border: none;
    color: #fff;
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: background 0.12s;
    box-shadow: 0 1px 3px rgba(23,57,115,.28);
    letter-spacing: 0.01em;
}
.btn-create:hover { background: var(--blue-hover); }
.btn-create:active { background: #0f2a5c; }
.btn-create:disabled {
    background: #6d88b8;
    box-shadow: none;
    cursor: not-allowed;
}

/* ── Queue card ──────────────────────────────────────────── */

.queue-card { padding: 16px 18px; }

.queue-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.queue-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink-2);
}

.queue-actions { display: flex; gap: 7px; }

.btn-submit-all {
    background: var(--blue);
    border: none;
    color: #fff;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.76rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.12s;
}
.btn-submit-all:hover { background: var(--blue-hover); }

.btn-discard-all {
    background: none;
    border: 1px solid var(--divider);
    color: var(--ink-4);
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.76rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s;
}
.btn-discard-all:hover { border-color: var(--ink-5); color: var(--ink-2); }

/* ── Draft list items ────────────────────────────────────── */

.draft-list { display: flex; flex-direction: column; gap: 6px; }

.draft-item {
    border: 1px solid var(--divider);
    border-radius: 9px;
    padding: 10px 13px;
    background: var(--surface-2);
}

.draft-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.draft-item-title {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--ink-4);
}

.draft-item-actions { display: flex; gap: 4px; }

.submit-draft-btn,
.edit-draft-btn,
.remove-draft-btn {
    background: none;
    border: 1px solid var(--divider);
    color: var(--ink-4);
    padding: 2px 8px;
    border-radius: 5px;
    font-size: 0.72rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.12s;
}
.submit-draft-btn { border-color: rgba(23,57,115,.35); color: var(--blue); }
.submit-draft-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); }
.edit-draft-btn:hover { border-color: var(--blue); color: var(--blue); }
.remove-draft-btn:hover { border-color: #ff3b30; color: #ff3b30; }

.draft-item-content {
    font-size: 0.84rem;
    color: var(--ink-3);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 60px;
    overflow: hidden;
    line-height: 1.45;
}

.draft-item-meta {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.draft-item-tag {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--blue);
    background: var(--blue-dim);
    padding: 1px 7px;
    border-radius: 20px;
}

.draft-item-flagged {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--orange);
    background: var(--orange-dim);
    padding: 1px 7px;
    border-radius: 20px;
}

/* ── Footer ──────────────────────────────────────────────── */

.site-footer {
    text-align: center;
    padding-top: 24px;
}

.footer-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.footer-sep { color: var(--ink-6); }

.help-link {
    font-size: 0.82rem;
    color: var(--ink-4);
    text-decoration: none;
    transition: color 0.12s;
}
.help-link:hover { color: var(--blue); }

.btn-sign-out {
    background: none;
    border: none;
    color: var(--ink-4);
    padding: 0;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.12s;
}
.btn-sign-out:hover { color: var(--ink-2); }

/* Keyboard shortcuts */
.keyboard-shortcuts {
    display: inline-block;
    margin-bottom: 12px;
}

.keyboard-shortcuts table {
    border-collapse: collapse;
}

.keyboard-shortcuts td {
    padding: 2px 10px;
    font-size: 0.76rem;
    line-height: 1.8;
}

.keyboard-shortcuts td.key {
    text-align: right;
    color: var(--ink-5);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.keyboard-shortcuts td.action {
    text-align: left;
    color: var(--ink-4);
}

.sign-out-hint {
    font-size: 0.74rem;
    color: var(--ink-5);
    margin-top: 4px;
    line-height: 1.4;
}

.unofficial-note {
    font-size: 0.72rem;
    color: var(--ink-5);
    margin-top: 16px;
    line-height: 1.4;
}

.unofficial-note a {
    color: var(--ink-4);
    text-decoration: underline;
    text-decoration-color: var(--divider);
}

/* ── Loading spinner ─────────────────────────────────────── */

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

.loading-spinner {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 1.5px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
    vertical-align: middle;
}

/* ── Setup mode — hide editor-only elements ──────────────── */

body.setup-mode .editor-only { display: none !important; }

/* ── Responsive ──────────────────────────────────────────── */

/* Mid-range: shrink tags max-width as space gets tighter */
@media (max-width: 680px) {
    .tags-field { max-width: 140px; }
}

@media (max-width: 560px) {
    .page-wrapper { padding: 0 12px 40px; }
    .form-meta-row { gap: 6px; }
    /* Allow meta-left to wrap on small screens — everything fits across two lines */
    .meta-left { flex-wrap: wrap; gap: 2px; }
    /* Tags takes full first row on narrow screens */
    .tags-field { max-width: none; flex: 1 1 100%; }
    .meta-right { gap: 6px; }
    .btn-sign-out { width: 100%; margin-top: 8px; }
    .footer-nav { flex-direction: column; gap: 6px; }
}

/* iPhone-width: stack meta row as two separate rows */
@media (max-width: 480px) {
    .form-meta-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 8px 12px;
    }
    .meta-left {
        overflow-x: auto;
        scrollbar-width: none;
        flex-wrap: nowrap;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--divider);
    }
    .meta-left::-webkit-scrollbar { display: none; }
    .tags-field { flex: 0 0 auto; max-width: 150px; }
    .meta-right {
        display: flex;
        justify-content: flex-end;
        padding-top: 8px;
        gap: 7px;
    }
}
