/* ═══════════════════════════════════════════════════════════════
   Docuty API Explorer – Styles
   ═══════════════════════════════════════════════════════════════ */

:root {
    --primary: #2563EB;
    --primary-hover: #1D4ED8;
    --accent: #0EA5E9;
    --success: #16A34A;
    --danger: #DC2626;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --border: #E2E8F0;
    --text: #0F172A;
    --text-muted: #64748B;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    margin: 0;
}

/* ── App Shell ─────────────────────────────────────────────────── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow);
}

.header-logo { text-decoration: none; display: flex; align-items: baseline; gap: 6px; }
.logo-text { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.logo-sub { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }

.header-nav { display: flex; align-items: center; gap: 1rem; }
.nav-link { text-decoration: none; color: var(--text-muted); font-weight: 500; padding: 6px 12px; border-radius: 6px; transition: all .15s; }
.nav-link:hover { background: var(--bg); color: var(--text); }
.nav-link.active { background: #EFF6FF; color: var(--primary); }

.app-main { flex: 1; padding: 2rem; max-width: 1100px; margin: 0 auto; width: 100%; }

.app-footer {
    padding: 1rem 2rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}
.footer-sep { margin: 0 .5rem; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn-connect {
    width: 100%; padding: 13px;
    background: var(--primary); color: #fff;
    border: none; border-radius: var(--radius);
    font-size: 1rem; font-weight: 600; cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: background .15s;
}
.btn-connect:hover:not(:disabled) { background: var(--primary-hover); }
.btn-connect:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
    padding: 8px 14px; background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-secondary:hover { background: var(--bg); border-color: #94A3B8; }

.btn-back { background: none; border: none; color: var(--text-muted); font-size: 0.9rem; cursor: pointer; padding: 4px 0; margin-bottom: .5rem; }
.btn-back:hover { color: var(--primary); }

.btn-disconnect {
    padding: 6px 12px; background: none; border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-muted); font-size: 0.85rem; cursor: pointer;
}
.btn-disconnect:hover { background: #FEF2F2; border-color: var(--danger); color: var(--danger); }

/* ── Forms ─────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.2rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 0.9rem; }
.form-control {
    width: 100%; padding: 11px 14px;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.95rem; outline: none; transition: border-color .15s; background: var(--surface);
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-control.is-invalid { border-color: var(--danger); }

.input-with-toggle { position: relative; display: flex; }
.input-with-toggle .form-control { padding-right: 44px; }
.toggle-btn { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 1rem; padding: 4px; }

.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 6px; }
.alert-error { background: #FEF2F2; border: 1px solid #FECACA; color: var(--danger); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 1rem; }

/* ── Spinners ──────────────────────────────────────────────────── */
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
.spinner-large { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Connect Page ──────────────────────────────────────────────── */
.connect-wrapper { min-height: calc(100vh - 60px); display: flex; align-items: center; justify-content: center; padding: 2rem; }
.connect-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); }
.connect-header { text-align: center; margin-bottom: 2rem; }
.connect-header h1 { font-size: 1.8rem; font-weight: 700; margin: 0 0 .5rem; }
.connect-header .accent { color: var(--primary); }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin: 0; }
.connect-form { margin-bottom: 2rem; }

.info-boxes { display: flex; flex-direction: column; gap: 12px; margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1.5rem; }
.info-box { display: flex; align-items: flex-start; gap: 12px; }
.info-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 2px; }
.info-box strong { display: block; font-size: 0.9rem; }
.info-box p { margin: 2px 0 0; font-size: 0.82rem; color: var(--text-muted); }

/* ── Page Header ───────────────────────────────────────────────── */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.page-header h2 { margin: 0 0 4px; font-size: 1.5rem; }
.page-subtitle { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

/* ── Stats Bar ─────────────────────────────────────────────────── */
.stats-bar { display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 20px; display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 100px; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--primary); line-height: 1; }
.stat-label { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

/* ── Audit Table ───────────────────────────────────────────────── */
.search-bar { margin-bottom: 1rem; }

.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.audit-table thead tr {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.audit-table th {
    padding: 11px 16px;
    text-align: left;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.audit-row {
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .1s;
}
.audit-row:last-child { border-bottom: none; }
.audit-row:hover { background: #F8FAFF; }
.audit-row:hover .row-open-link { opacity: 1; }

.audit-table td {
    padding: 13px 16px;
    vertical-align: middle;
}

.col-title { font-weight: 500; color: var(--text); }
.col-form  { color: var(--text-muted); }
.col-user  { color: var(--text-muted); }
.col-date  { color: var(--text-muted); white-space: nowrap; font-size: 0.85rem; }
.col-entries { color: var(--text-muted); text-align: center; font-size: 0.85rem; }
.col-status { white-space: nowrap; }
.col-action { text-align: right; width: 80px; }

.row-open-link {
    font-size: 0.82rem;
    color: var(--primary);
    font-weight: 500;
    opacity: 0;
    transition: opacity .15s;
    white-space: nowrap;
}

/* ── Status Badge ──────────────────────────────────────────────── */
.status-badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: #F1F5F9; color: #475569; }
.status-done, .status-completed, .status-finished { background: #DCFCE7; color: #15803D; }
.status-open, .status-active { background: #DBEAFE; color: #1D4ED8; }
.status-draft { background: #F1F5F9; color: #475569; }
.status-archived { background: #F3F4F6; color: #6B7280; }

/* ── Detail Page ───────────────────────────────────────────────── */
.detail-header { margin-bottom: 1.5rem; }
.detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.detail-title-row h2 { margin: 4px 0 6px; font-size: 1.4rem; }
.detail-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-muted); }
.export-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Section Card ──────────────────────────────────────────────── */
.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.2rem; box-shadow: var(--shadow); }
.section-title { margin: 0 0 1rem; font-size: 1rem; font-weight: 600; }

/* ── Fields ────────────────────────────────────────────────────── */
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.field-item { background: var(--bg); border-radius: 8px; padding: 10px 14px; }
.field-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; margin-bottom: 3px; }
.field-value { font-size: 0.9rem; font-weight: 500; word-break: break-word; }
.type-tag { font-size: 0.7rem; background: #E0E7FF; color: #3730A3; border-radius: 4px; padding: 1px 6px; margin-left: 6px; font-weight: 500; }

/* ── JSON Panel ────────────────────────────────────────────────── */
.json-panel { background: #0F172A; color: #E2E8F0; border-color: #1E293B; }
.json-panel .section-title { color: #94A3B8; }
.json-header { margin-bottom: 1rem; }
.json-hint { font-size: 0.82rem; color: #64748B; margin: 4px 0 0; }
.json-output { margin: 0; font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 0.8rem; overflow-x: auto; white-space: pre; color: #7DD3FC; line-height: 1.6; max-height: 500px; overflow-y: auto; }

/* ── Entry Cards ───────────────────────────────────────────────── */
.entry-card { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; overflow: hidden; }
.entry-header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; background: var(--bg); user-select: none; transition: background .1s; }
.entry-header:hover { background: #F1F5F9; }
.entry-number { font-weight: 600; font-size: 0.9rem; flex-shrink: 0; }
.entry-meta { flex: 1; font-size: 0.82rem; color: var(--text-muted); }
.toggle-icon { color: var(--text-muted); font-size: 0.75rem; }
.image-badge { background: #FEF3C7; color: #92400E; border-radius: 20px; padding: 1px 8px; margin-left: 8px; font-size: 0.78rem; }
.entry-body { padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); }

/* ── Image Gallery ─────────────────────────────────────────────── */
.image-gallery { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.image-wrapper { border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.entry-image { max-width: 260px; max-height: 200px; display: block; object-fit: cover; }
.image-placeholder { width: 120px; height: 90px; background: var(--bg); border: 1px dashed var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 0.82rem; color: var(--text-muted); transition: border-color .15s; }
.image-placeholder:hover { border-color: var(--primary); color: var(--primary); }

/* ── Integration Hint ──────────────────────────────────────────── */
.integration-hint { display: flex; gap: 14px; align-items: flex-start; background: #EFF6FF; border: 1px solid #BFDBFE; border-radius: var(--radius); padding: 1.2rem 1.4rem; margin-top: 1.5rem; }
.hint-icon { font-size: 1.4rem; flex-shrink: 0; }
.integration-hint strong { font-size: 0.95rem; display: block; margin-bottom: 4px; color: #1E40AF; }
.integration-hint p { margin: 0; font-size: 0.85rem; color: #1E40AF; opacity: .85; }

/* ── Toast ─────────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 2rem; right: 2rem; z-index: 999; background: #1E293B; color: #fff; padding: 12px 20px; border-radius: 10px; font-size: 0.9rem; box-shadow: var(--shadow-lg); animation: fadeInUp .3s ease; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ── Empty / Loading States ────────────────────────────────────── */
.loading-state { text-align: center; padding: 4rem 2rem; color: var(--text-muted); }
.loading-state p { margin-top: 1rem; }
.empty-state { text-align: center; padding: 4rem 2rem; }
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { margin: 0 0 .5rem; }
.empty-state p { color: var(--text-muted); }
.empty-state-small { color: var(--text-muted); font-size: 0.9rem; text-align: center; padding: 1.5rem; }

.initial-loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.initial-loading-inner { text-align: center; color: var(--text-muted); }
.initial-loading-inner p { margin-top: 1rem; }

/* ── Blazor Error UI ───────────────────────────────────────────── */
#blazor-error-ui { background: #FEF2F2; border-top: 1px solid #FECACA; color: var(--danger); display: none; bottom: 0; box-sizing: border-box; left: 0; padding: 12px 16px; position: fixed; width: 100%; z-index: 1000; font-size: 0.9rem; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; font-weight: bold; opacity: .5; }
#blazor-error-ui .dismiss:hover { opacity: 1; }
