/* =========================================================
   main.css — Villatent Contract Tooling
   ========================================================= */

/* ----- CSS Custom Properties ----- */
:root {
    --primary:       #2563eb;
    --primary-dark:  #1d4ed8;
    --primary-light: #dbeafe;
    --bg:            #f1f5f9;
    --surface:       #ffffff;
    --surface-alt:   #f8fafc;
    --text:          #0f172a;
    --text-muted:    #64748b;
    --border:        #e2e8f0;
    --danger:        #dc2626;
    --success:       #16a34a;
    --warning:       #d97706;
    --radius:        0.5rem;
    --shadow-sm:     0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow:        0 4px 12px rgba(0, 0, 0, 0.10);
    --nav-height:    60px;
    --sidebar-width: 220px;
    --font:          'Inter', system-ui, -apple-system, sans-serif;
}

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

html { font-size: 16px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

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

img, svg { display: block; }

/* ----- Navigation ----- */
.nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 2rem;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav__brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    white-space: nowrap;
}

.nav__links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.nav__link {
    padding: 0.4rem 0.85rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav__link:hover,
.nav__link.active {
    background: var(--primary-light);
    color: var(--primary);
    text-decoration: none;
}

.nav__user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-left: auto;
}

.nav__user a {
    color: var(--danger);
    font-weight: 500;
}

/* ----- Page Layout ----- */
.page {
    margin-top: var(--nav-height);
    padding: 2rem 1.5rem;
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text);
}

/* ----- Cards ----- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.card__label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.card__value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.card__sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

/* ----- Metric Grid ----- */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

/* ----- Forms ----- */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.35rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

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

/* ----- Buttons ----- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn:hover { text-decoration: none; }

.btn--primary {
    background: var(--primary);
    color: #fff;
}
.btn--primary:hover { background: var(--primary-dark); }

.btn--secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn--secondary:hover { background: var(--bg); }

.btn--success {
    background: var(--success);
    color: #fff;
}
.btn--success:hover { background: #15803d; }

.btn--danger {
    background: var(--danger);
    color: #fff;
}
.btn--danger:hover { background: #b91c1c; }

.btn--sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

/* ----- Tables ----- */
.table-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

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

thead {
    background: var(--surface-alt);
    border-bottom: 2px solid var(--border);
}

th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover { background: var(--surface-alt); cursor: pointer; }

/* ----- Status Badge ----- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge--pending  { background: #fef3c7; color: #92400e; }
.badge--extracted { background: #dbeafe; color: #1e40af; }
.badge--confirmed { background: #dcfce7; color: #14532d; }
.badge--failed   { background: #fee2e2; color: #7f1d1d; }

/* ----- Toolbar (above table) ----- */
.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.toolbar input[type="text"],
.toolbar select {
    width: auto;
    flex: 1;
    min-width: 180px;
}

/* ----- Drag & Drop Zone ----- */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    background: var(--surface);
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}

.drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone__icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.drop-zone__text {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.drop-zone__text strong { color: var(--primary); }

/* ----- Progress / Status ----- */
.status-bar {
    display: none;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius);
    margin-top: 1rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.status-bar--info    { background: var(--primary-light); color: var(--primary); }
.status-bar--success { background: #dcfce7; color: var(--success); }
.status-bar--error   { background: #fee2e2; color: var(--danger); }

/* ----- Split view (review page) ----- */
.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 800px) {
    .split { grid-template-columns: 1fr; }
}

/* ----- Chat / Q&A ----- */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--nav-height) - 4rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-msg {
    max-width: 80%;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.6;
}

.chat-msg--user {
    background: var(--primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 0;
}

.chat-msg--assistant {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    align-self: flex-start;
    border-bottom-left-radius: 0;
}

.chat-content p { margin: 0 0 0.5rem 0; }
.chat-content p:last-child { margin-bottom: 0; }
.chat-content h3, .chat-content h4 { margin: 0.75rem 0 0.25rem 0; font-size: 0.95rem; }
.chat-content ul { margin: 0.25rem 0 0.5rem 0; padding-left: 1.25rem; }
.chat-content li { margin-bottom: 0.2rem; }
.chat-content strong { font-weight: 600; }

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    padding: 0.85rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.chat-input-row textarea {
    flex: 1;
    min-height: unset;
    height: 44px;
    resize: none;
    font-size: 0.9rem;
}

/* ----- Citations ----- */
.citations {
    margin-top: 0.6rem;
}

.citation-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.citation-list {
    display: none;
    margin-top: 0.5rem;
    padding: 0.6rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.citation-list.open { display: block; }

/* ----- Login page ----- */
.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.login-card__title {
    font-size: 1.4rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 1.75rem;
    color: var(--text);
}

/* ----- Error list ----- */
.errorlist {
    list-style: none;
    color: var(--danger);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

/* ----- Misc utilities ----- */
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 0.85rem; }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }
.mb-3  { margin-bottom: 1.5rem; }
.flex  { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 1rem; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* Dashboard card variants */
.card--warning { border-left: 4px solid var(--warning); }
.card--danger  { border-left: 4px solid var(--danger); }
.card--info    { border-left: 4px solid var(--primary); }

/* Compare table */
.compare-check { width: 16px; height: 16px; }

/* ----- Responsive ----- */
@media (max-width: 640px) {
    .page { padding: 1.25rem 1rem; }
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .nav__links { display: none; }
}
