/* ============================================================
   CLM Pilot — Dashboard Stylesheet
   ============================================================ */

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

:root {
    --primary:      #2563eb;
    --primary-dark:  #1d4ed8;
    --primary-light: #dbeafe;
    --success:       #16a34a;
    --success-light: #dcfce7;
    --warning:       #d97706;
    --warning-light: #fef3c7;
    --danger:        #dc2626;
    --danger-light:  #fee2e2;
    --info:          #0891b2;
    --info-light:    #cffafe;
    --gray-50:       #f9fafb;
    --gray-100:      #f3f4f6;
    --gray-200:      #e5e7eb;
    --gray-300:      #d1d5db;
    --gray-400:      #9ca3af;
    --gray-500:      #6b7280;
    --gray-600:      #4b5563;
    --gray-700:      #374151;
    --gray-800:      #1f2937;
    --gray-900:      #111827;
    --sidebar-w:     250px;
    --header-h:      56px;
    --radius:        8px;
    --shadow-sm:     0 1px 2px rgba(0,0,0,.05);
    --shadow:        0 1px 3px rgba(0,0,0,.1), 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,.1), 0 4px 6px rgba(0,0,0,.05);
    --transition:    .2s ease;
}

html { font-size: 14px; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* --- Layout --- */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--gray-900);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
}
.sidebar-brand {
    padding: 16px 20px;
    font-size: 1.15rem;
    font-weight: 700;
    border-bottom: 1px solid var(--gray-700);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-brand .icon { font-size: 1.4rem; }
.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px;
    color: var(--gray-300);
    font-size: .92rem;
    transition: background var(--transition), color var(--transition);
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.sidebar-nav a.active {
    background: rgba(37,99,235,.15);
    color: #fff;
    border-left-color: var(--primary);
    font-weight: 600;
}
.sidebar-nav .nav-section {
    padding: 18px 20px 6px;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--gray-500);
}
.sidebar-user {
    padding: 14px 20px;
    border-top: 1px solid var(--gray-700);
    font-size: .85rem;
    display: flex; align-items: center; justify-content: space-between;
}
.sidebar-user .username { color: var(--gray-300); }
.sidebar-user a { color: var(--gray-400); font-size: .8rem; }

/* Main Content */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
}

/* Top Bar */
.topbar {
    height: var(--header-h);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h1 { font-size: 1.15rem; font-weight: 600; color: var(--gray-900); }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.btn-sidebar-toggle {
    display: none;
    background: none; border: none; font-size: 1.3rem;
    cursor: pointer; color: var(--gray-600); padding: 4px;
}

/* Alert Bell */
.alert-bell {
    position: relative; cursor: pointer;
    font-size: 1.2rem; color: var(--gray-500);
    transition: color var(--transition);
}
.alert-bell:hover { color: var(--gray-700); }
.alert-bell .badge {
    position: absolute; top: -6px; right: -8px;
    background: var(--danger); color: #fff;
    font-size: .65rem; font-weight: 700;
    min-width: 16px; height: 16px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}

/* Page Body */
.page-body { padding: 24px; }

/* --- Cards & Panels --- */
.card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    font-size: .95rem;
    display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 18px; }
.card-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: 0 0 var(--radius) var(--radius);
}

/* Stat Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 18px;
    display: flex; align-items: flex-start; gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem; flex-shrink: 0;
}
.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.red    { background: var(--danger-light);  color: var(--danger); }
.stat-icon.cyan   { background: var(--info-light);    color: var(--info); }
.stat-info { flex: 1; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; color: var(--gray-900); }
.stat-label { font-size: .8rem; color: var(--gray-500); margin-top: 2px; }

/* Grid Helpers */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 24px; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
}
thead th {
    background: var(--gray-50);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}
thead th a { color: var(--gray-600); }
thead th a:hover { color: var(--primary); text-decoration: none; }
tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
tbody tr:hover { background: var(--gray-50); }
tbody tr:last-child td { border-bottom: none; }

.table-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-400);
    font-size: .95rem;
}

/* --- Badges --- */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-blue   { background: var(--primary-light); color: var(--primary); }
.badge-green  { background: var(--success-light); color: var(--success); }
.badge-orange { background: var(--warning-light); color: var(--warning); }
.badge-red    { background: var(--danger-light);  color: var(--danger); }
.badge-gray   { background: var(--gray-200);      color: var(--gray-600); }
.badge-cyan   { background: var(--info-light);     color: var(--info); }

/* Risk levels */
.risk-high   { color: var(--danger);  font-weight: 600; }
.risk-medium { color: var(--warning); font-weight: 600; }
.risk-low    { color: var(--success); font-weight: 600; }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    font-size: .88rem;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: #fff; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-lg { padding: 10px 24px; font-size: 1rem; }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 5px;
}
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: .9rem;
    color: var(--gray-800);
    background: #fff;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.form-inline { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.form-inline .form-group { margin-bottom: 0; }

/* --- Search / Filter Bar --- */
.filter-bar {
    display: flex; align-items: flex-end; gap: 12px;
    flex-wrap: wrap;
    padding: 14px 18px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-control { min-width: 160px; }

/* --- Pagination --- */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 4px;
    padding: 14px 0;
}
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 34px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: .85rem;
    font-weight: 500;
    color: var(--gray-600);
    transition: all var(--transition);
}
.pagination a:hover { background: var(--gray-100); color: var(--primary); text-decoration: none; }
.pagination .active { background: var(--primary); color: #fff; font-weight: 600; }
.pagination .disabled { color: var(--gray-300); cursor: default; }

/* --- Alerts / Notices --- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: .9rem;
    display: flex; align-items: flex-start; gap: 10px;
}
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-danger  { background: var(--danger-light);  color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: var(--info-light);     color: #155e75; border: 1px solid #a5f3fc; }

/* Dismissible alerts list on dashboard */
.alert-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--gray-100);
    font-size: .88rem;
    gap: 10px;
}
.alert-item:last-child { border-bottom: none; }
.alert-item .alert-msg { flex: 1; }
.alert-item .alert-date { color: var(--gray-400); font-size: .78rem; white-space: nowrap; }
.alert-item .btn-dismiss {
    background: none; border: none; color: var(--gray-400);
    cursor: pointer; font-size: 1.1rem; padding: 2px 6px;
}
.alert-item .btn-dismiss:hover { color: var(--danger); }

/* --- Upload Zone --- */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--gray-50);
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.upload-zone .upload-icon { font-size: 2.5rem; color: var(--gray-400); margin-bottom: 10px; }
.upload-zone .upload-text { font-size: 1rem; color: var(--gray-600); margin-bottom: 4px; }
.upload-zone .upload-hint { font-size: .82rem; color: var(--gray-400); }
.upload-zone input[type="file"] { display: none; }

/* File Queue */
.upload-queue { margin-top: 16px; }
.upload-file-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    margin-bottom: 8px;
}
.upload-file-item .file-name { flex: 1; font-weight: 500; font-size: .9rem; }
.upload-file-item .file-size { color: var(--gray-400); font-size: .8rem; }
.upload-file-item .file-status { font-size: .8rem; font-weight: 600; }
.upload-file-item .file-status.queued   { color: var(--gray-400); }
.upload-file-item .file-status.uploading { color: var(--primary); }
.upload-file-item .file-status.processing { color: var(--warning); }
.upload-file-item .file-status.completed { color: var(--success); }
.upload-file-item .file-status.failed   { color: var(--danger); }

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}
.progress-bar .progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width .4s ease;
}
.progress-bar .progress-fill.success { background: var(--success); }
.progress-bar .progress-fill.warning { background: var(--warning); }

/* --- Chat / Ask AI --- */
.chat-layout { display: flex; height: calc(100vh - var(--header-h)); }

.chat-sidebar {
    width: 260px;
    border-right: 1px solid var(--gray-200);
    background: #fff;
    display: flex; flex-direction: column;
    flex-shrink: 0;
}
.chat-sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; justify-content: space-between;
}
.chat-sidebar-header h3 { font-size: .9rem; font-weight: 600; }
.chat-history {
    flex: 1; overflow-y: auto; padding: 8px;
}
.chat-history-item {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: .85rem;
    cursor: pointer;
    margin-bottom: 2px;
    color: var(--gray-600);
    transition: background var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-history-item:hover { background: var(--gray-100); }
.chat-history-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 24px;
    display: flex; flex-direction: column; gap: 16px;
}
.chat-msg {
    max-width: 720px;
    line-height: 1.6;
}
.chat-msg.user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    padding: 10px 16px;
    border-radius: 14px 14px 4px 14px;
}
.chat-msg.assistant {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--gray-200);
    padding: 14px 18px;
    border-radius: 14px 14px 14px 4px;
    box-shadow: var(--shadow-sm);
}
.chat-msg.assistant .msg-sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--gray-100);
    font-size: .8rem;
    color: var(--gray-500);
}
.chat-msg.assistant .msg-confidence {
    margin-top: 6px;
    font-size: .78rem;
}
.confidence-high   { color: var(--success); }
.confidence-medium { color: var(--warning); }
.confidence-low    { color: var(--gray-400); }

.chat-suggestions {
    padding: 0 24px 12px;
    display: flex; gap: 8px; flex-wrap: wrap;
}
.suggestion-chip {
    padding: 6px 14px;
    border: 1px solid var(--gray-200);
    border-radius: 20px;
    font-size: .82rem;
    color: var(--gray-600);
    cursor: pointer;
    background: #fff;
    transition: all var(--transition);
}
.suggestion-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    background: #fff;
}
.chat-input-wrap {
    display: flex; gap: 10px; align-items: flex-end;
}
.chat-input-wrap textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: .92rem;
    resize: none;
    max-height: 120px;
    font-family: inherit;
}
.chat-input-wrap textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex; gap: 4px; padding: 10px 16px;
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: 14px; align-self: flex-start;
}
.typing-indicator span {
    width: 7px; height: 7px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* --- Contract Detail --- */
.detail-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.detail-header h2 { font-size: 1.3rem; font-weight: 700; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.detail-field label {
    display: block; font-size: .78rem;
    text-transform: uppercase; letter-spacing: .04em;
    color: var(--gray-500); margin-bottom: 2px;
}
.detail-field .value { font-size: .95rem; color: var(--gray-800); font-weight: 500; }

/* --- Renewal Timeline --- */
.renewal-group { margin-bottom: 24px; }
.renewal-group-header {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 10px;
}
.renewal-group-header h3 { font-size: .95rem; font-weight: 600; }
.renewal-group-header .count { font-size: .8rem; color: var(--gray-400); }

/* --- Admin Panel --- */
.health-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.health-item {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    background: #fff; border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}
.health-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.health-dot.healthy { background: var(--success); }
.health-dot.unhealthy { background: var(--danger); }
.health-label { font-size: .9rem; font-weight: 500; }

/* --- Login Page --- */
.login-wrapper {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    padding: 20px;
}
.login-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: 36px;
}
.login-card .logo {
    text-align: center;
    margin-bottom: 24px;
}
.login-card .logo h1 { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.login-card .logo p { font-size: .88rem; color: var(--gray-500); margin-top: 4px; }
.login-card .form-group { margin-bottom: 18px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; font-size: .95rem; }
.login-error {
    background: var(--danger-light);
    color: #991b1b;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: .88rem;
    margin-bottom: 16px;
    text-align: center;
}

/* --- Utilities --- */
.text-muted { color: var(--gray-500); }
.text-sm { font-size: .82rem; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Chart containers */
.chart-container {
    position: relative;
    height: 250px;
    width: 100%;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .chat-sidebar { width: 200px; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .btn-sidebar-toggle { display: block; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar .form-control { min-width: auto; }

    .chat-layout { flex-direction: column; }
    .chat-sidebar { width: 100%; height: auto; max-height: 200px; border-right: none; border-bottom: 1px solid var(--gray-200); }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .page-body { padding: 16px; }
    .login-card { padding: 24px; }
}

/* --- Print --- */
@media print {
    .sidebar, .topbar, .chat-input-area, .btn, .filter-bar { display: none !important; }
    .main-content { margin-left: 0; }
    .page-body { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}
