/*
 * Hugo — MHDBDB Interface
 * Main Stylesheet
 *
 * Palette: warm parchment, deep ink, burgundy accent.
 * Typography: EB Garamond (headings), Source Sans 3 (body/UI).
 */

/* ==========================================================================
   CSS Custom Properties
   ========================================================================== */

:root {
    /* Parchment palette */
    --parchment-light  : #FAF6EE;
    --parchment        : #F2EBD9;
    --parchment-mid    : #E8DEC8;
    --parchment-dark   : #D8CCAF;

    /* Ink palette */
    --ink-darkest      : #1A0F08;
    --ink-dark         : #2C1A10;
    --ink-mid          : #4A3728;
    --ink-light        : #7A6555;
    --ink-faint        : #A89880;

    /* Accent — deep burgundy */
    --accent           : #7B1D1D;
    --accent-hover     : #5E1515;
    --accent-light     : #F5EAEA;
    --accent-border    : #C47A7A;

    /* Greens for success states */
    --success          : #2E5C3E;
    --success-light    : #EAF3EE;

    /* Functional */
    --border           : #C8B896;
    --border-light     : #DDD0B8;
    --shadow           : rgba(44, 26, 16, 0.12);
    --shadow-deep      : rgba(44, 26, 16, 0.22);

    /* Typography */
    --font-heading     : 'EB Garamond', Georgia, serif;
    --font-body        : 'Source Sans 3', 'Segoe UI', system-ui, sans-serif;
    --font-mono        : 'Courier New', Courier, monospace;

    /* Layout */
    --header-height    : 56px;
    --input-height     : 92px;
    --sidebar-width    : 360px;
    --radius-sm        : 4px;
    --radius-md        : 8px;
    --radius-lg        : 12px;
}

/* ==========================================================================
   Reset and Base
   ========================================================================== */

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

html, body {
    height: 100%;
    font-family: var(--font-body);
    font-size: 16px;
    color: var(--ink-dark);
    background: var(--parchment);
}

/* ==========================================================================
   Gothic interlace strip — decorative top border
   ========================================================================== */

body::before {
    content: '';
    display: block;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: repeating-linear-gradient(
        90deg,
        var(--accent)        0px,
        var(--accent)        8px,
        var(--parchment-dark) 8px,
        var(--parchment-dark) 12px,
        var(--accent-border) 12px,
        var(--accent-border) 16px,
        var(--parchment-dark) 16px,
        var(--parchment-dark) 20px
    );
    z-index: 1000;
}

/* ==========================================================================
   App layout
   ========================================================================== */

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding-top: 4px; /* clear the interlace strip */
    overflow: hidden;
}

/* ==========================================================================
   Header
   ========================================================================== */

.app-header {
    height: var(--header-height);
    background: var(--ink-darkest);
    border-bottom: 2px solid var(--accent);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    flex-shrink: 0;
    z-index: 100;
}

/* Brand */
.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-logo {
    width: 34px;
    height: 34px;
    background: var(--accent);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--parchment-light);
    letter-spacing: 0.02em;
}

.header-titles {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.header-name {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--parchment-light);
    letter-spacing: 0.04em;
}

.header-subtitle {
    font-size: 0.7rem;
    color: var(--ink-faint);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* Actions */
.header-actions {
    display: flex;
    gap: 8px;
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
}

/* User info */
.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.header-username {
    font-size: 0.85rem;
    color: var(--parchment-mid);
}

.header-role-badge {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 2px 6px;
    background: var(--accent);
    color: var(--parchment-light);
    border-radius: 10px;
}

.header-logout {
    font-size: 0.8rem;
    color: var(--ink-faint);
    text-decoration: none;
    padding: 4px 8px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.header-logout:hover {
    color: var(--parchment-light);
    border-color: rgba(255,255,255,0.25);
}

/* ==========================================================================
   Schema panel
   ========================================================================== */

.schema-panel {
    background: var(--parchment-light);
    border-bottom: 1px solid var(--border);
    max-height: 280px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    box-shadow: 0 4px 12px var(--shadow);
}

.schema-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--parchment-mid);
    border-bottom: 1px solid var(--border);
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--ink-dark);
    flex-shrink: 0;
}

.schema-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink-light);
    font-size: 0.9rem;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.schema-close-btn:hover { background: var(--parchment-dark); }

.schema-panel-body {
    overflow-y: auto;
    padding: 16px 20px;
    font-size: 0.82rem;
    color: var(--ink-mid);
    white-space: pre-wrap;
    font-family: var(--font-mono);
    line-height: 1.5;
    flex: 1;
}

.schema-loading { font-family: var(--font-body); color: var(--ink-faint); }

/* ==========================================================================
   Response area
   ========================================================================== */

.response-area {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: var(--parchment);
    /* Faint paper texture via noise */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
}

/* ==========================================================================
   Welcome state
   ========================================================================== */

.welcome-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    max-width: 680px;
    margin: 0 auto;
    width: 100%;
}

.welcome-logo {
    width: 64px;
    height: 64px;
    background: var(--accent);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 2.4rem;
    font-weight: 500;
    color: var(--parchment-light);
    margin-bottom: 16px;
    box-shadow: 0 4px 16px var(--shadow-deep);
}

.welcome-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 500;
    color: var(--ink-dark);
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.welcome-text {
    font-size: 0.95rem;
    color: var(--ink-light);
    line-height: 1.6;
    margin-bottom: 28px;
    max-width: 480px;
}

.welcome-examples {
    width: 100%;
}

.examples-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-faint);
    margin-bottom: 12px;
}

.example-chip {
    display: inline-block;
    margin: 4px;
    padding: 6px 14px;
    background: var(--parchment-light);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--ink-mid);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.example-chip:hover {
    background: var(--accent-light);
    border-color: var(--accent-border);
    color: var(--accent);
}

/* ==========================================================================
   Conversation turns
   ========================================================================== */

.turn {
    display: flex;
    gap: 14px;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

.turn-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    flex-shrink: 0;
    margin-top: 2px;
}

.turn-avatar-user {
    background: var(--parchment-mid);
    border: 1px solid var(--border);
    color: var(--ink-mid);
}

.turn-avatar-hugo {
    background: var(--accent);
    border: 1px solid var(--accent-hover);
    color: var(--parchment-light);
}

.turn-body { flex: 1; min-width: 0; }

.turn-sender {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-faint);
    margin-bottom: 6px;
}

.turn-text {
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--ink-dark);
}

/* Question bubble */
.turn-question .turn-body {
    background: var(--parchment-mid);
    border: 1px solid var(--border-light);
    border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
    padding: 12px 16px;
}

/* Result turn */
.turn-result .turn-body,
.turn-message .turn-body {
    background: var(--parchment-light);
    border: 1px solid var(--border-light);
    border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
    padding: 14px 16px;
}

/* Error turn */
.turn-error .turn-body {
    background: #FDF2F2;
    border: 1px solid #DEB8B8;
    border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
    padding: 14px 16px;
}

.error-message {
    font-size: 0.9rem;
    color: var(--accent);
    line-height: 1.6;
}

/* Result summary and meta */
.result-summary {
    font-size: 0.92rem;
    color: var(--ink-mid);
    line-height: 1.6;
    margin-bottom: 10px;
}

.result-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.result-count {
    font-size: 0.78rem;
    color: var(--ink-faint);
    background: var(--parchment-mid);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 2px 10px;
}

.result-truncation-notice {
    font-size: 0.78rem;
    color: var(--accent);
    padding: 6px 10px;
    background: var(--accent-light);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

/* SQL disclosure block */
.sql-block {
    margin: 8px 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--ink-mid);
}

.sql-pre {
    background: var(--ink-darkest);
    color: #D4C9A8;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.55;
    padding: 14px 16px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

/* ==========================================================================
   Result table
   ========================================================================== */

.result-table-container {
    overflow-x: auto;
    margin-top: 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}

.result-table thead tr {
    background: var(--accent);
}

.result-table thead th {
    padding: 8px 12px;
    text-align: left;
    color: var(--parchment-light);
    font-weight: 500;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    border-right: 1px solid rgba(255,255,255,0.15);
}

.result-table thead th:last-child { border-right: none; }

.result-table tbody tr:nth-child(odd)  { background: var(--parchment-light); }
.result-table tbody tr:nth-child(even) { background: var(--parchment-mid); }
.result-table tbody tr:hover           { background: var(--accent-light); }

.result-table tbody td {
    padding: 7px 12px;
    color: var(--ink-dark);
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-table tbody td:last-child { border-right: none; }

/* ==========================================================================
   Thinking indicator
   ========================================================================== */

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0 10px 50px;
    color: var(--ink-light);
    font-size: 0.9rem;
    font-style: italic;
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
}

.thinking-quill {
    font-size: 1.1rem;
    animation: quill-pulse 1.4s ease-in-out infinite;
}

@keyframes quill-pulse {
    0%, 100% { opacity: 1; transform: translateY(0); }
    50%       { opacity: 0.5; transform: translateY(-2px); }
}

/* ==========================================================================
   Input area
   ========================================================================== */

.input-area {
    flex-shrink: 0;
    background: var(--parchment-light);
    border-top: 2px solid var(--border);
    padding: 14px 32px 12px;
    box-shadow: 0 -4px 16px var(--shadow);
}

.input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 860px;
    margin: 0 auto;
}

.question-textarea {
    flex: 1;
    resize: none;
    padding: 10px 14px;
    font-family: var(--font-body);
    font-size: 0.95rem;
    color: var(--ink-dark);
    background: var(--parchment);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    line-height: 1.5;
    transition: border-color 0.2s, box-shadow 0.2s;
    max-height: 160px;
    overflow-y: auto;
}

.question-textarea:focus {
    outline: none;
    border-color: var(--accent-border);
    box-shadow: 0 0 0 3px rgba(123, 29, 29, 0.1);
}

.question-textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.send-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    padding: 0;
}

.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.input-hint {
    font-size: 0.72rem;
    color: var(--ink-faint);
    text-align: center;
    margin-top: 6px;
    max-width: 860px;
    margin-left: auto;
    margin-right: auto;
}

.input-hint kbd {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 1px 5px;
    background: var(--parchment-mid);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--ink-mid);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 16px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: var(--parchment-light);
    border: 1px solid var(--accent-hover);
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    background: rgba(255,255,255,0.08);
    color: var(--parchment-mid);
    border: 1px solid rgba(255,255,255,0.15);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.14);
    color: var(--parchment-light);
}

.btn-ghost {
    background: transparent;
    color: var(--ink-light);
    border: 1px solid var(--border-light);
}

.btn-ghost:hover {
    background: var(--parchment-mid);
    color: var(--ink-dark);
}

.btn-sm   { padding: 5px 12px; font-size: 0.78rem; }
.btn-block { width: 100%; }

/* ==========================================================================
   Login page
   ========================================================================== */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--parchment);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

.login-card {
    background: var(--parchment-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 32px var(--shadow-deep);
}

.login-header {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo {
    width: 56px;
    height: 56px;
    background: var(--accent);
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 500;
    color: var(--parchment-light);
    margin-bottom: 14px;
    box-shadow: 0 4px 14px var(--shadow-deep);
}

.login-title {
    font-family: var(--font-heading);
    font-size: 1.9rem;
    font-weight: 500;
    color: var(--ink-dark);
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 0.78rem;
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.login-error {
    background: #FDF2F2;
    border: 1px solid #DEB8B8;
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 0.85rem;
    padding: 10px 14px;
    margin-bottom: 18px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; }

.login-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 0.72rem;
    color: var(--ink-faint);
    letter-spacing: 0.02em;
}

/* ==========================================================================
   Form elements (shared between login and any future modals)
   ========================================================================== */

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--ink-mid);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.form-input {
    padding: 10px 13px;
    font-family: var(--font-body);
    font-size: 0.92rem;
    color: var(--ink-dark);
    background: var(--parchment);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-border);
    box-shadow: 0 0 0 3px rgba(123, 29, 29, 0.1);
}

/* ==========================================================================
   Scrollbar styling (Webkit)
   ========================================================================== */

::-webkit-scrollbar              { width: 6px; height: 6px; }
::-webkit-scrollbar-track        { background: var(--parchment); }
::-webkit-scrollbar-thumb        { background: var(--parchment-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover  { background: var(--ink-faint); }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 420px) {
    .header-subtitle,
    .header-actions       { display: none; }
    .response-area        { padding: 16px; }
    .input-area           { padding: 10px 16px; }
    .input-hint           { display: none; }
    .turn                 { gap: 8px; }
    .result-table td,
    .result-table th      { padding: 6px 8px; font-size: 0.78rem; }
}
