/* ============================================================
 * lcsh-saas — shadcn-flavored UI
 *
 * Beige Brown & Green palette (schemecolor.com):
 *   #A6705C  terracotta brown
 *   #C9B262  warm beige/gold
 *   #D9C91A  mustard
 *   #6D9778  sage green (primary accent)
 *   #437154  medium forest green
 *   #314730  deep forest green
 *
 * Design tokens follow shadcn/ui naming:
 *   --background / --foreground
 *   --card / --muted / --accent / --primary / --destructive
 *   --border / --input / --ring
 *   --radius
 * ============================================================ */

:root {
    /* Surfaces */
    --background:           #FAF7EE;
    --foreground:           #2A2620;
    --card:                 #FFFFFF;
    --card-foreground:      #2A2620;
    --popover:              #FFFFFF;
    --popover-foreground:   #2A2620;

    /* Brand */
    --primary:              #437154;          /* deep sage — buttons / links */
    --primary-foreground:   #FFFFFF;
    --primary-hover:        #314730;

    /* Secondary tan (chip-style) */
    --secondary:            #EFE7D2;
    --secondary-foreground: #4A4030;

    /* Muted surfaces */
    --muted:                #F2EDDE;
    --muted-foreground:     #7A6E58;

    /* Accent (warm beige highlight) */
    --accent:               #E6DABA;
    --accent-foreground:    #3A311E;

    /* Status */
    --success:              #437154;
    --success-bg:           #DBEADE;
    --warning:              #8E7220;          /* readable gold-brown */
    --warning-bg:           #F6EFD3;
    --destructive:          #B5503B;          /* terracotta-red */
    --destructive-bg:       #F4DCD3;
    --destructive-foreground: #FFFFFF;

    /* Borders / inputs / focus */
    --border:               #E5DAC0;
    --border-strong:        #C7B996;
    --input:                #E5DAC0;
    --ring:                 rgba(67, 113, 84, 0.35);

    /* Code */
    --code-bg:              #F2EDDE;
    --code-fg:              #3A311E;

    /* Typography */
    --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
                 "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

    /* Geometry */
    --radius-sm: 0.375rem;   /* 6px  */
    --radius:    0.5rem;     /* 8px  */
    --radius-lg: 0.75rem;    /* 12px */

    /* Shadows (subtle, shadcn-style) */
    --shadow-sm: 0 1px 2px 0 rgba(34, 30, 24, 0.04);
    --shadow:    0 1px 3px 0 rgba(34, 30, 24, 0.06), 0 1px 2px -1px rgba(34, 30, 24, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(34, 30, 24, 0.07), 0 2px 4px -2px rgba(34, 30, 24, 0.05);
}

/* ---- reset / base ---- */

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

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    color: var(--foreground);
    background: var(--background);
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3, h4 { letter-spacing: -0.011em; line-height: 1.25; color: var(--foreground); }
h1 { font-size: 1.5rem;  font-weight: 600; margin: 0 0 0.75rem; }
h2 { font-size: 1.125rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
h3 { font-size: 1rem;     font-weight: 600; margin: 1rem 0 0.5rem; }

p { margin: 0 0 0.75rem; }

.lead { color: var(--muted-foreground); font-size: 0.9375rem; }
.lead small { color: var(--muted-foreground); }

::selection { background: var(--accent); color: var(--accent-foreground); }

/* ---- header ---- */

header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem 2rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

header .brand {
    font-weight: 600;
    font-size: 1rem;
    color: var(--foreground);
    text-decoration: none;
    letter-spacing: -0.01em;
}
header .brand:hover { text-decoration: none; color: var(--primary); }

header nav { display: flex; gap: 0.25rem; }
header nav a {
    color: var(--muted-foreground);
    text-decoration: none;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.1s, color 0.1s;
}
header nav a:hover { background: var(--muted); color: var(--foreground); }

header .header-spacer { flex: 1; }
header .user-area { display: flex; align-items: center; gap: 0.75rem; }
header .user-email {
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    font-variant-numeric: tabular-nums;
}

/* ---- main / footer ---- */

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

footer {
    max-width: 1100px;
    margin: 1.5rem auto 1.5rem;
    padding: 0 2rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* ---- buttons ---- */

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    background: var(--primary);
    color: var(--primary-foreground);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.1s, color 0.1s, border-color 0.1s, box-shadow 0.1s;
    box-shadow: var(--shadow-sm);
}
button:hover, .button:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--primary-foreground);
    text-decoration: none;
}
button:focus-visible, .button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Outline / ghost button variant (apply with .button.button-outline) */
.button-outline {
    background: var(--card);
    color: var(--foreground);
    border-color: var(--border-strong);
}
.button-outline:hover {
    background: var(--muted);
    color: var(--foreground);
    border-color: var(--border-strong);
}

/* ---- forms ---- */

input[type="text"], input[type="number"], input[type="email"],
input[type="password"], select, textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--foreground);
    background: var(--card);
    border: 1px solid var(--input);
    border-radius: var(--radius);
    transition: border-color 0.1s, box-shadow 0.1s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}

input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
}

.upload-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 720px;
    margin-top: 1rem;
}

.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.form-row label {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--foreground);
    flex: 1;
    min-width: 180px;
}
.form-row label input,
.form-row label select { font-weight: 400; }

/* ---- dropzone ---- */

.dropzone {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 2.5rem 1.5rem;
    text-align: center;
    background: var(--card);
    color: var(--muted-foreground);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    font-size: 0.9375rem;
}
.dropzone:hover, .dropzone.drag {
    border-color: var(--primary);
    background: var(--muted);
    color: var(--foreground);
}
.dropzone input { display: none; }

/* ---- code / pre ---- */

code, pre, .marc {
    font-family: var(--font-mono);
    background: var(--code-bg);
    color: var(--code-fg);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
}
code { padding: 0.1rem 0.375rem; }
pre, .marc {
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    overflow-x: auto;
    line-height: 1.55;
}

/* ---- tables ---- */

table {
    width: 100%;
    margin-top: 0.75rem;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
th, td {
    text-align: left;
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    font-size: 0.875rem;
}
th {
    background: var(--muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted-foreground);
}
tbody tr { transition: background 0.08s; }
tbody tr:hover { background: var(--muted); }
tr:last-child td { border-bottom: none; }

.records-table td:nth-child(1) { color: var(--muted-foreground); width: 40px; }
.records-table td:nth-child(2) { font-family: var(--font-mono); font-size: 0.75rem; }

/* ---- badges (shadcn-style pill) ---- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
    background: var(--muted);
    color: var(--muted-foreground);
    border: 1px solid transparent;
}
.badge-running, .badge-queued {
    background: var(--warning-bg);
    color: var(--warning);
}
.badge-completed, .badge-done {
    background: var(--success-bg);
    color: var(--success);
}
.badge-failed, .badge-error {
    background: var(--destructive-bg);
    color: var(--destructive);
}
.badge-pending {
    background: var(--muted);
    color: var(--muted-foreground);
}

.err { color: var(--destructive); }

.warn-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--warning-bg);
    color: var(--warning);
}

/* ---- definition list (job/record metadata) ---- */

dl.meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.375rem 1.25rem;
    margin: 0.5rem 0 1.5rem;
    padding: 1rem 1.25rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    font-size: 0.875rem;
}
dl.meta dt { color: var(--muted-foreground); font-weight: 500; }
dl.meta dd { margin: 0; color: var(--foreground); }

/* ---- actions row ---- */

.actions { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }

/* ---- template-link pill ---- */

.template-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.625rem;
    background: var(--accent);
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--accent-foreground);
    transition: background 0.1s;
}
.template-link:hover {
    background: var(--secondary);
    color: var(--accent-foreground);
    text-decoration: none;
}

/* ---- transcript (rendered markdown) ---- */

.transcript {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem 1.75rem;
    margin-top: 0.75rem;
}
.transcript h1 { font-size: 1.25rem; margin-top: 0; }
.transcript h2 {
    font-size: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 1.5rem;
}
.transcript h3 { font-size: 0.9375rem; }
.transcript table { font-size: 0.8125rem; box-shadow: none; }
.transcript table th { font-size: 0.6875rem; }
.transcript blockquote {
    border-left: 3px solid var(--primary);
    padding: 0.25rem 0 0.25rem 1rem;
    color: var(--muted-foreground);
    margin: 1rem 0;
    background: var(--muted);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.transcript code { font-size: 0.8125rem; }
.transcript pre { background: var(--code-bg); }
.transcript ul, .transcript ol { padding-left: 1.5rem; }

/* ---- Clerk sign-in embedded widget ---- */

#clerk-signin { margin: 1rem 0; max-width: 480px; }
#clerk-user-button { display: flex; align-items: center; }
