@import url('https://fonts.googleapis.com/css2?family=Raleway:wght@500;700;800&family=Playfair+Display:wght@400;600;700&family=Inter:wght@300;400;500;600&display=swap');

/* ═══════════════════════════════════════════════════════════
   JurisArticles Admin — Premium Legal Dashboard CSS
   ═══════════════════════════════════════════════════════════ */

:root {
    --primary: #c29b57;
    --primary-hover: #a17d3d;
    --primary-light: rgba(194, 155, 87, 0.12);
    --danger: #ef4444;
    --success: #10b981;
    --info: #3b82f6;
    --warning: #f59e0b;

    /* Light Theme */
    --bg-main: #eef2f7;
    --bg-card: #ffffff;
    --bg-sidebar: #0B1120;
    --sidebar-text: #94a3b8;
    --sidebar-active: #ffffff;
    --text-main: #1a202c;
    --text-muted: #64748b;
    --border-color: #e2e8f0;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --radius: 12px;
}

[data-theme="dark"] {
    --bg-main: #111827;
    --bg-card: #1e293b;
    --bg-sidebar: #0B1120;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #1e293b;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}

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

body {
    font-family: 'Inter', sans-serif;
    background:
      radial-gradient(900px 420px at 18% -10%, rgba(194,155,87,0.20), transparent 60%),
      radial-gradient(720px 360px at 88% 8%, rgba(59,130,246,0.14), transparent 58%),
      linear-gradient(180deg, #f7f9fc 0%, #edf2f7 100%);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

h1, h2, h3, h4 {
    font-family: 'Playfair Display', serif;
    color: var(--text-main);
}

a { text-decoration: none; color: inherit; }

/* ═══════════ GLASS PANEL ═══════════ */
.glass-panel {
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius);
}

/* ═══════════ LOGIN VIEW ═══════════ */
.login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--bg-main);
    min-height: 100vh;
    width: 100%;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 3rem 2.5rem;
}

.login-header { text-align: center; margin-bottom: 2.5rem; }
.login-logo {
    font-size: 2rem;
    font-weight: 800;
    font-family: 'Raleway', sans-serif;
    color: var(--primary);
    margin-bottom: 0.5rem;
}
.logo-strong { font-weight: 800; letter-spacing: 0.01em; }
.logo-soft { font-weight: 500; opacity: .78; margin-left: .15rem; }

/* ═══════════ FORMS ═══════════ */
.form-group { margin-bottom: 1.5rem; }
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-main);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.form-full { grid-column: 1 / -1; }

/* ═══════════ BUTTONS ═══════════ */
.btn-primary {
    background: var(--primary);
    color: #fff;
    padding: 0.85rem 1.75rem;
    border-radius: 8px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-align: center;
    font-size: 0.95rem;
    transition: background 0.2s, transform 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-full { width: 100%; }
.btn-google {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: .5rem;
    background: #fff;
    color: #111827;
    border: 1px solid #d1d5db;
    padding: 0.85rem 1.75rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}
.btn-google:hover { border-color: #9ca3af; background: #f9fafb; }
.btn-secondary {
    background: transparent;
    color: var(--text-main);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-size: 0.9rem;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; padding: 0.5rem 1rem; border-radius: 8px; border: none; cursor: pointer; font-size: 0.85rem; }
.btn-danger:hover { opacity: 0.9; }

/* ═══════════ ADMIN LAYOUT ═══════════ */
.admin-layout { display: flex; width: 100%; min-height: 100vh; }

/* Sidebar — Dark Navy always */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    border-right: 1px solid rgba(255,255,255,0.05);
}

.sidebar-logo {
    padding: 2rem 1.5rem;
    font-size: 1.35rem;
    font-weight: 800;
    font-family: 'Raleway', sans-serif;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    line-height: 1.1;
}
.sidebar-logo small { display:block; font-size:.7rem; font-weight:600; opacity:.75; letter-spacing:.08em; margin-top:.2rem; }

.sidebar-nav {
    flex-grow: 1;
    padding: 1.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.sidebar-divider {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.06);
    margin: 0.75rem 1rem;
}

.sidebar-section-label {
    padding: 0.5rem 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.25);
    margin-top: 0.5rem;
}

.sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* Main content */
.main-content {
    flex-grow: 1;
    margin-left: 260px;
    padding: 2rem 2.5rem;
    position: relative;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    background: rgba(255,255,255,0.72);
    border: 1px solid rgba(255,255,255,0.7);
    border-radius: 14px;
    padding: 0.9rem 1rem;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 1.75rem; }

.user-info { display: flex; align-items: center; gap: 1rem; }
.user-info span { font-size: 0.9rem; color: var(--text-muted); }

.btn-logout {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}
.btn-logout:hover { background: var(--bg-card); color: var(--danger); border-color: var(--danger); }

/* ═══════════ KPI DASHBOARD ═══════════ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

.kpi-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.kpi-icon {
    width: 54px; height: 54px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.6rem;
    background: var(--primary-light);
}

.kpi-value {
    font-size: 1.85rem;
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
    margin-bottom: 0.2rem;
}
.kpi-label { font-size: 0.8rem; color: var(--text-muted); }

/* ═══════════ ENTITY CARDS ═══════════ */
.cards-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

.entity-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column;
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
}
.card-title { font-weight: 600; font-family: 'Playfair Display', serif; font-size: 1rem; }
.card-body { padding: 0; flex-grow: 1; }
.card-footer {
    padding: 1rem 1.5rem;
    background: var(--bg-main);
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem; color: var(--text-muted);
    display: flex; justify-content: space-between;
}

.btn-small-edit { font-size: 0.8rem; color: var(--info); background: rgba(59,130,246,0.08); padding: 0.3rem 0.85rem; border-radius: 99px; border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.btn-small-danger { font-size: 0.8rem; color: var(--danger); background: rgba(239,68,68,0.08); padding: 0.3rem 0.85rem; border-radius: 99px; border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

/* Status Badges */
.status-badge {
    padding: 0.25rem 0.75rem; border-radius: 99px;
    font-size: 0.72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
    display: inline-block;
}
.status-publicado, .status-ativo, .status-admin, .status-superadmin { background: rgba(16,185,129,0.08); color: var(--success); }
.status-rascunho, .status-novo, .status-user { background: rgba(245,158,11,0.08); color: var(--warning); }
.status-pendente { background: rgba(59,130,246,0.08); color: var(--info); }
.status-concluido { background: rgba(16,185,129,0.08); color: var(--success); }
.status-cancelado { background: rgba(239,68,68,0.08); color: var(--danger); }
.status-urgente { background: rgba(239,68,68,0.08); color: var(--danger); }

/* ═══════════ AGENDA STYLES ═══════════ */
.agenda-tabs {
    display: flex; gap: 0; border-bottom: 2px solid var(--border-color); margin-bottom: 2rem;
}
.agenda-tab {
    padding: 1rem 1.75rem;
    font-weight: 500; font-size: 0.95rem;
    color: var(--text-muted);
    cursor: pointer; border: none; background: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.agenda-tab:hover { color: var(--text-main); }
.agenda-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Event list */
.event-list { display: flex; flex-direction: column; gap: 1rem; }
.event-item {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius); padding: 1.25rem 1.5rem;
    display: flex; justify-content: space-between; align-items: center;
    transition: border-color 0.2s;
}
.event-item:hover { border-color: var(--primary); }
.event-item.priority-urgente { border-left: 4px solid var(--danger); }
.event-item.priority-alta { border-left: 4px solid var(--warning); }
.event-item.priority-normal { border-left: 4px solid var(--info); }

.event-info h4 { font-size: 1rem; margin-bottom: 0.35rem; font-family: 'Inter', sans-serif; font-weight: 600; }
.event-meta { font-size: 0.85rem; color: var(--text-muted); display: flex; gap: 1.5rem; }
.event-actions { display: flex; gap: 0.5rem; }

/* Notes grid */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.25rem; }
.note-card {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius); padding: 1.5rem;
    border-top: 4px solid var(--primary);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}
.note-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.note-card.pinned { border-top-color: var(--warning); }
.note-card h4 { font-size: 1rem; margin-bottom: 0.75rem; font-family: 'Inter', sans-serif; }
.note-card p { font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; }
.note-card .note-date { font-size: 0.75rem; color: var(--text-muted); margin-top: 1rem; }
.note-pin { position: absolute; top: 0.75rem; right: 0.75rem; font-size: 1rem; cursor: pointer; }

.notes-grid {
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
}
.legal-note-card {
    padding: 1.1rem 1.15rem 1rem;
    border-radius: 18px;
    border-width: 1px;
    box-shadow: 0 12px 26px rgba(15,23,42,0.08);
}
.legal-note-head {
    margin-bottom: .65rem;
}
.legal-note-label {
    font-size: .86rem;
    color: #475569;
    display: inline-block;
}
.legal-note-head h4 {
    margin-top: .2rem;
    margin-bottom: 0;
    font-family: 'Raleway', sans-serif;
    font-size: 2rem;
    line-height: 1.1;
    font-weight: 800;
    letter-spacing: .01em;
    color: #0f172a;
    word-break: break-word;
}
.legal-note-row {
    display: flex;
    flex-wrap: wrap;
    gap: .6rem 1.6rem;
    font-size: 1.18rem;
    line-height: 1.5;
    color: #1e293b;
    margin-bottom: .55rem;
}
.legal-note-block {
    margin-top: .35rem;
    margin-bottom: .55rem;
}
.legal-note-block label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: .15rem;
    color: #0f172a;
}
.legal-note-subtitle {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: .2rem;
}
.legal-note-content {
    margin: 0;
    font-size: 1.08rem;
    line-height: 1.65;
    color: #0f172a;
    white-space: pre-wrap;
}
.legal-note-foot {
    margin-top: .65rem;
    margin-bottom: .2rem;
}
.legal-note-updated {
    font-size: 1.05rem;
    color: #334155;
    margin-bottom: .7rem;
}
.legal-note-actions {
    display: flex;
    gap: .5rem;
}

/* ═══════════ AI CHAT ═══════════ */
.ai-hero-legal {
    background:
      linear-gradient(125deg, rgba(11,17,32,0.96), rgba(24,36,62,0.94)),
      radial-gradient(circle at 18% 18%, rgba(194,155,87,0.32), transparent 42%);
    color: #f8fafc;
    border-radius: 16px;
    padding: 1.5rem 1.6rem;
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 1rem;
    border: 1px solid rgba(255,255,255,0.14);
    box-shadow: 0 16px 28px rgba(15,23,42,0.18);
    margin-bottom: 1rem;
}
.ai-hero-legal h3 {
    color: #fff;
    margin: .35rem 0 .4rem;
    font-family: 'Raleway', sans-serif;
    font-size: 1.35rem;
    letter-spacing: .01em;
}
.ai-hero-legal p {
    color: rgba(241,245,249,.88);
    font-size: .95rem;
    line-height: 1.6;
}
.ai-hero-badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .11em;
    font-weight: 700;
    border: 1px solid rgba(194,155,87,.45);
    color: #f5deb3;
    border-radius: 999px;
    padding: .35rem .7rem;
    background: rgba(194,155,87,.12);
}
.ai-hero-metrics {
    display: grid;
    grid-template-columns: 1fr;
    gap: .7rem;
}
.ai-metric-card {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 12px;
    padding: .75rem .9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .7rem;
}
.ai-metric-card span {
    color: rgba(226,232,240,.82);
    font-size: .78rem;
}
.ai-metric-card strong {
    color: #fff;
    font-size: .85rem;
    font-family: 'Raleway', sans-serif;
}

.codex-legal-shell {
    display: grid;
    gap: 1rem;
}
.codex-legal-top {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: .9rem;
    padding: 1rem 1.1rem;
    border-radius: 14px;
    border: 1px solid rgba(148,163,184,.28);
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: 0 8px 20px rgba(15,23,42,.07);
}
.codex-brand h3 {
    font-family: 'Raleway', sans-serif;
    font-size: 1.26rem;
    margin: .28rem 0;
}
.codex-brand p {
    color: var(--text-muted);
    font-size: .9rem;
}
.codex-brand-badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(194,155,87,.38);
    border-radius: 999px;
    padding: .24rem .6rem;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .08em;
    color: #8a652d;
    background: rgba(194,155,87,.1);
}
.codex-top-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: .55rem;
}
.codex-top-card {
    border: 1px solid rgba(148,163,184,.32);
    border-radius: 10px;
    padding: .55rem .65rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
}
.codex-top-card span {
    font-size: .75rem;
    color: var(--text-muted);
}
.codex-top-card strong {
    font-size: .82rem;
    color: #0f172a;
}

.codex-legal-grid {
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr) 340px;
    gap: 1.2rem;
    align-items: start;
}
.codex-left,
.codex-right {
    min-width: 0;
}
.codex-left {
    position: sticky;
    top: 1rem;
}
.codex-right {
    position: sticky;
    top: 1rem;
}
.codex-panel {
    border: 1px solid rgba(148,163,184,.25);
    border-radius: 12px;
    background: rgba(255,255,255,.86);
    padding: .7rem;
    box-shadow: 0 8px 16px rgba(15,23,42,.06);
}
.codex-chat {
    min-height: 72vh;
}
.codex-chat.ai-chat-container.legal-chat {
    height: auto;
    min-height: 76vh;
}
.codex-chat-header {
    padding: .8rem 1rem;
}
.codex-chat-title-wrap {
    display: flex;
    align-items: center;
    gap: .5rem;
}
.codex-chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    align-items: center;
    justify-content: flex-end;
}
.codex-chat-messages {
    padding: 1rem;
}
.codex-file-bar {
    padding: .55rem .85rem;
}
.codex-compose {
    padding: .7rem .85rem;
}
.codex-flow {
    margin-top: .7rem;
}

.ai-workbench-grid {
    display: grid;
    grid-template-columns: 390px 1fr;
    gap: 1rem;
    align-items: start;
}

.ai-side-panel {
    background: rgba(255,255,255,0.86);
    border: 1px solid rgba(148,163,184,0.24);
    border-radius: var(--radius);
    padding: 1rem;
    backdrop-filter: blur(6px);
    box-shadow: 0 8px 18px rgba(15,23,42,0.08);
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 115px);
    overflow: auto;
}
.ai-history-card {
    border: 1px solid rgba(148,163,184,0.28);
    border-radius: 12px;
    background: rgba(255,255,255,0.82);
    padding: .65rem;
}
.ai-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .5rem;
}
.ai-history-tools {
    display: grid;
    gap: .45rem;
    margin-bottom: .55rem;
}
.ai-history-search {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: .5rem .65rem;
    font-size: .83rem;
    background: #fff;
    color: var(--text-main);
}
.ai-history-search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.ai-history-filters {
    display: flex;
    gap: .4rem;
}
.ai-filter-btn {
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-muted);
    border-radius: 999px;
    padding: .28rem .56rem;
    font-size: .74rem;
    cursor: pointer;
}
.ai-filter-btn.active {
    color: #8a652d;
    border-color: rgba(194,155,87,.52);
    background: rgba(194,155,87,.14);
}
.ai-btn-mini {
    padding: .45rem .7rem;
    font-size: .78rem;
    line-height: 1;
}
.ai-conversation-list {
    max-height: 300px;
    overflow: auto;
    display: grid;
    gap: .35rem;
    padding-right: .1rem;
}
.ai-conversation-item {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: #fff;
    padding: .45rem .5rem;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: .35rem;
    transition: border-color .15s, transform .12s, background .15s, box-shadow .15s;
}
.ai-conversation-actions {
    display: inline-flex;
    align-items: center;
    gap: .28rem;
}
.ai-conversation-item:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(15,23,42,.08);
}
.ai-conversation-item.active {
    border-color: var(--primary);
    background: rgba(194,155,87,0.1);
}
.ai-conversation-open {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    padding: .08rem .18rem;
    display: grid;
    gap: .15rem;
    cursor: pointer;
}
.ai-conversation-item strong {
    font-size: .82rem;
    color: #0f172a;
    font-weight: 700;
    display: block;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.ai-conversation-item span {
    font-size: .72rem;
    color: var(--text-muted);
}
.ai-fav-btn {
    border: 1px solid var(--border-color);
    background: #fff;
    color: #94a3b8;
    border-radius: 8px;
    width: 30px;
    height: 30px;
    line-height: 1;
    font-size: 1rem;
    cursor: pointer;
    transition: all .15s;
}
.ai-fav-btn:hover {
    border-color: #f59e0b;
    color: #f59e0b;
}
.ai-fav-btn.active {
    border-color: #f59e0b;
    background: rgba(245,158,11,.12);
    color: #b45309;
}
.ai-del-btn {
    border: 1px solid rgba(239,68,68,.35);
    background: #fff;
    color: #ef4444;
    border-radius: 8px;
    width: 30px;
    height: 30px;
    line-height: 1;
    font-size: .85rem;
    cursor: pointer;
    font-weight: 700;
}
.ai-del-btn:hover {
    background: rgba(239,68,68,.12);
}
.ai-empty-history {
    color: var(--text-muted);
    font-size: .8rem;
    padding: .45rem .35rem;
}
.ai-side-panel h4 {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: .95rem;
    margin-bottom: .6rem;
}
.ai-fold {
    margin-top: .8rem;
    border: 1px solid rgba(148,163,184,0.26);
    border-radius: 11px;
    background: rgba(255,255,255,0.78);
    padding: .5rem .6rem .65rem;
}
.ai-fold summary {
    list-style: none;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: .88rem;
    font-weight: 700;
    color: #0f172a;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .2rem .1rem .4rem;
}
.ai-fold summary::-webkit-details-marker {
    display: none;
}
.ai-fold summary::after {
    content: '+';
    font-size: 1rem;
    color: var(--text-muted);
}
.ai-fold[open] summary::after {
    content: '-';
}
.ai-context-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem;
}
.ai-context-grid .form-group {
    margin-bottom: 0;
}
.ai-context-grid .form-group:nth-child(odd):last-child {
    grid-column: 1 / -1;
}
.ai-template-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: .45rem;
}
.ai-template-btn {
    border: 1px solid var(--border-color);
    background: #fff;
    border-radius: 10px;
    padding: .58rem .7rem;
    text-align: left;
    font-size: .86rem;
    color: #334155;
    cursor: pointer;
    transition: border-color .15s, transform .15s, background .15s;
}
.ai-template-btn:hover {
    border-color: var(--primary);
    background: #f8fafc;
    transform: translateY(-1px);
}
.ai-flow-card {
    margin-top: .85rem;
    padding: .75rem .85rem;
    border-radius: 10px;
    border: 1px dashed rgba(11,17,32,0.24);
    background: rgba(11,17,32,0.03);
    display: grid;
    gap: .2rem;
}
.ai-flow-card strong {
    font-size: .88rem;
}
.ai-flow-card span {
    font-size: .8rem;
    color: var(--text-muted);
}

.ai-chat-container {
    display: flex; flex-direction: column;
    height: calc(100vh - 220px);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}
.ai-chat-container.legal-chat {
    height: calc(100vh - 330px);
    min-height: 600px;
}

.ai-chat-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    background: rgba(255,255,255,0.82);
    backdrop-filter: blur(4px);
}
.ai-chat-header h3 { font-family: 'Inter', sans-serif; font-weight: 600; font-size: 1rem; }

.ai-chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex; flex-direction: column; gap: 1.25rem;
    background: linear-gradient(180deg, rgba(241,245,249,.55) 0%, rgba(248,250,252,.2) 100%);
}

.ai-msg {
    max-width: 88%;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
    line-height: 1.7;
    white-space: pre-wrap;
    box-shadow: 0 4px 14px rgba(15,23,42,.06);
}
.ai-msg.user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-msg.assistant {
    align-self: flex-start;
    background: var(--bg-main);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}
.ai-msg.ai-thinking {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-style: italic;
    color: #334155;
}
.ai-dots {
    display: inline-flex;
    gap: .22rem;
}
.ai-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #64748b;
    display: inline-block;
    animation: aiBlink 1.05s infinite ease-in-out;
}
.ai-dots i:nth-child(2) { animation-delay: .12s; }
.ai-dots i:nth-child(3) { animation-delay: .24s; }
@keyframes aiBlink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-1px); }
}

.ai-chat-input {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex; gap: 0.75rem;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(4px);
}
.ai-chat-input textarea {
    flex-grow: 1;
    resize: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.85rem 1rem;
    background: var(--bg-main);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    min-height: 48px;
    max-height: 120px;
}
.ai-chat-input textarea:focus { outline: none; border-color: var(--primary); }
.ai-chat-input button {
    background: var(--primary);
    color: #fff; border: none;
    border-radius: 10px;
    padding: 0 1.3rem;
    font-weight: 600; cursor: pointer;
    white-space: nowrap;
    min-width: 88px;
    box-shadow: 0 8px 18px rgba(194,155,87,.28);
}
.ai-chat-input button:hover { background: var(--primary-hover); }
.ai-chat-input button:disabled { opacity: 0.5; cursor: not-allowed; }

.ai-quick-actions {
    display: flex; gap: 0.5rem; flex-wrap: wrap;
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border-color);
}
.ai-quick-btn {
    padding: 0.4rem 1rem;
    border-radius: 99px;
    font-size: 0.8rem;
    background: var(--primary-light);
    color: var(--primary);
    border: none; cursor: pointer;
    font-weight: 500;
}
.ai-quick-btn:hover { background: var(--primary); color: #fff; }

/* Modal */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 999;
}
.modal-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 550px;
    box-shadow: var(--shadow-md);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-card h2 { margin-bottom: 1.5rem; }

/* Toasts */
.toast-container {
    position: fixed; bottom: 2rem; right: 2rem;
    z-index: 9999; display: flex; flex-direction: column; gap: 0.75rem;
}
.toast {
    background: var(--bg-card); color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem; border-radius: 8px;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s cubic-bezier(0.16,1,0.3,1) forwards;
    display: flex; align-items: center; font-size: 0.9rem;
}
.ai-msg.ai-welcome {
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    border-left: 4px solid var(--primary);
}
.ai-chip {
    border: 1px solid rgba(148,163,184,.36);
    color: var(--text-muted);
    border-radius: 999px;
    padding: .3rem .55rem;
    font-size: .75rem;
}
.ai-processing-badge {
    border: 1px solid rgba(14,165,233,.4);
    color: #0369a1;
    background: rgba(14,165,233,.1);
    border-radius: 999px;
    padding: .28rem .56rem;
    font-size: .74rem;
    font-weight: 600;
}
.ai-export-select {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: .36rem .5rem;
    font-size: .8rem;
    background: #fff;
    color: var(--text-main);
}

.ai-chat-files {
    display: flex;
    gap: .5rem;
    align-items: center;
    padding: .7rem 1rem;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    background: rgba(248,250,252,0.95);
}
.ai-file-input {
    display: none;
}
.ai-upload-btn {
    padding: .55rem .85rem;
    font-size: .86rem;
}
.ai-file-picked {
    font-size: .8rem;
    color: var(--text-muted);
}
.ai-selected-files {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-left: auto;
}
.ai-file-chip {
    border: 1px solid rgba(194,155,87,.45);
    background: rgba(194,155,87,.12);
    color: #8a652d;
    border-radius: 999px;
    padding: .22rem .5rem;
    font-size: .74rem;
}
.ai-file-empty {
    font-size: .8rem;
    color: var(--text-muted);
}

.integrations-card {
    background: rgba(255,255,255,0.82);
    border: 1px solid rgba(148,163,184,0.24);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: 0 6px 20px rgba(15,23,42,0.06);
    backdrop-filter: blur(5px);
}

.agenda-tabs {
    background: rgba(255,255,255,0.55);
    border-radius: 12px 12px 0 0;
    padding: 0 .65rem;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 900px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 1.5rem; }
    .cards-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .ai-hero-legal { grid-template-columns: 1fr; }
    .ai-workbench-grid { grid-template-columns: 1fr; }
    .ai-side-panel { position: static; max-height: none; overflow: visible; }
    .ai-context-grid { grid-template-columns: 1fr; }
    .ai-chat-container.legal-chat { min-height: 70vh; height: auto; }
    .ai-chat-container { height: calc(100vh - 180px); }
    .ai-selected-files { margin-left: 0; width: 100%; }
    .codex-legal-top { grid-template-columns: 1fr; }
    .codex-legal-grid { grid-template-columns: 1fr; }
    .codex-left, .codex-right { position: static; top: auto; }
    .codex-left { order: 2; }
    .codex-center { order: 1; }
    .codex-right { order: 3; }
    .codex-chat.ai-chat-container.legal-chat { min-height: 64vh; }
    .notes-grid { grid-template-columns: 1fr; }
    .legal-note-head h4 { font-size: 1.5rem; }
    .legal-note-row { font-size: 1rem; }
    .legal-note-content { font-size: .98rem; }
}

@media (max-width: 1480px) and (min-width: 901px) {
    .codex-legal-grid { grid-template-columns: 280px minmax(0, 1fr); }
    .codex-right { grid-column: 1 / -1; position: static; top: auto; }
    .codex-left { position: static; top: auto; }
}
