/* ============ RESET ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f1f5f9;
    color: #0f172a;
    font-size: 14px;
    line-height: 1.5;
}
a { color: #25d366; text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; font-family: "SF Mono", Consolas, monospace; }
.small { font-size: 11px; }
.muted { color: #64748b; }

/* ============ AUTH ============ */
.auth-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.auth-card {
    background: white;
    padding: 40px;
    border-radius: 16px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.2);
}
.auth-card h1 { font-size: 28px; margin-bottom: 6px; text-align: center; }
.auth-subtitle { color: #64748b; margin-bottom: 24px; text-align: center; }
.auth-hint { font-size: 12px; color: #94a3b8; margin-top: 16px; text-align: center; }

/* ============ LAYOUT ============ */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px;
    background: #0f172a;
    color: #cbd5e1;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
}
.brand {
    font-size: 20px;
    font-weight: 800;
    padding: 0 20px 20px;
    border-bottom: 1px solid #1e293b;
    color: white;
}
.sidebar nav {
    flex: 1;
    padding: 16px 0;
    display: flex;
    flex-direction: column;
}
.sidebar nav a {
    color: #cbd5e1;
    padding: 12px 20px;
    display: block;
    text-decoration: none;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}
.sidebar nav a:hover { background: #1e293b; color: white; }
.sidebar nav a.active {
    background: #25d366;
    color: white;
    border-left: 3px solid #128c7e;
}
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid #1e293b;
}
.user-info { font-size: 13px; color: white; margin-bottom: 8px; font-weight: 600; }
.logout {
    color: #94a3b8;
    font-size: 13px;
    text-decoration: none;
}
.logout:hover { color: #ef4444; }

.content {
    margin-left: 240px;
    flex: 1;
    padding: 30px;
    max-width: calc(100vw - 240px);
}

/* ============ FLASH ============ */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 18px;
    font-size: 14px;
    border-left: 3px solid;
}
.flash-success { background: #ecfdf5; color: #065f46; border-color: #10b981; }
.flash-error   { background: #fef2f2; color: #991b1b; border-color: #ef4444; }
.flash-info    { background: #eff6ff; color: #1e40af; border-color: #3b82f6; }

/* ============ HEADERS ============ */
h1 { font-size: 26px; margin-bottom: 20px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}
.page-header h1 { margin-bottom: 0; }

/* ============ STAT CARDS ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: white;
    padding: 22px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}
.stat-card.success { background: linear-gradient(135deg, #25d366, #128c7e); color: white; border: none; }
.stat-card .stat-num { font-size: 32px; font-weight: 800; margin-bottom: 4px; }
.stat-card .stat-label { font-size: 13px; color: #64748b; }
.stat-card.success .stat-label { color: rgba(255,255,255,0.9); }

/* ============ CARD ============ */
.card {
    background: white;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin-bottom: 20px;
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}
.card-header h2 { margin: 0; font-size: 16px; }
.card.highlight { border-color: #f59e0b; }
.card.highlight .card-header { background: #fef3c7; }
.card.highlight-success { border-color: #25d366; }
.card.highlight-success .card-header { background: #d1fae5; }

/* ============ TABLE ============ */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    font-size: 13px;
}
.table th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover { background: #f8fafc; }
.empty { text-align: center; color: #94a3b8; padding: 40px !important; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============ BADGE ============ */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    background: #e2e8f0;
    color: #475569;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-info    { background: #dbeafe; color: #1e40af; }

/* ============ BUTTONS ============ */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid #e2e8f0;
    background: white;
    color: #0f172a;
    text-decoration: none;
    transition: all 0.2s;
    font-family: inherit;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn-primary { background: #25d366; color: white; border-color: #25d366; }
.btn-primary:hover { background: #128c7e; border-color: #128c7e; color: white; }
.btn-danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.btn-danger:hover { background: #ef4444; color: white; border-color: #ef4444; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; display: block; text-align: center; }

/* ============ FORM ============ */
.form { padding: 20px; }
.card .form { padding: 20px; }
.field { margin-bottom: 18px; }
.field label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 13px;
    color: #334155;
}
.field input[type=text],
.field input[type=email],
.field input[type=password],
.field input[type=url],
.field input[type=number],
.field select,
.field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: white;
    transition: border-color 0.2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: #25d366;
    box-shadow: 0 0 0 3px rgba(37,211,102,0.1);
}
.field textarea { resize: vertical; min-height: 80px; }
.field small {
    display: block;
    font-size: 12px;
    color: #94a3b8;
    margin-top: 4px;
}
.field small a { color: #25d366; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-row-3 { grid-template-columns: repeat(3, 1fr); }

.checkbox-field { display: flex; align-items: center; }
.checkbox-field label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500 !important;
    margin-bottom: 0 !important;
}
.checkbox-field input[type=checkbox] { width: 18px; height: 18px; cursor: pointer; }

.form .actions {
    padding: 16px 0 0;
    display: flex;
    gap: 10px;
}
.inline-form select { padding: 6px 10px; border-radius: 6px; border: 1px solid #e2e8f0; }

/* ============ INFO BOX ============ */
.info-box {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 14px 18px;
    font-size: 13px;
    margin-bottom: 18px;
}
.info-box code {
    background: white;
    padding: 4px 8px;
    border-radius: 4px;
    word-break: break-all;
    display: inline-block;
    margin-top: 4px;
}

/* ============ DOCS LIST ============ */
.docs-list { padding-top: 12px; border-top: 1px solid #e2e8f0; margin-top: 16px; }
.doc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 13px;
}

/* ============ CHAT ============ */
.chat-container {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
}
.chat-messages {
    padding: 20px;
    background: #f0f2f5;
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.msg {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}
.msg-meta { font-size: 11px; color: #64748b; margin-bottom: 4px; }
.msg-body { white-space: pre-wrap; word-wrap: break-word; }
.msg-in { background: white; align-self: flex-start; }
.msg-ai { background: #dcf8c6; align-self: flex-end; }
.msg-op { background: #d4eaff; align-self: flex-end; }
.msg-sys {
    background: #fef3c7;
    align-self: center;
    text-align: center;
    font-size: 12px;
    max-width: 90%;
    border: 1px solid #fcd34d;
}
.chat-input {
    padding: 14px;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 10px;
    background: white;
}
.chat-input textarea {
    flex: 1;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
    .sidebar {
        width: 60px;
        padding: 10px 0;
    }
    .brand { font-size: 24px; padding: 10px; text-align: center; }
    .brand span { display: none; }
    .sidebar nav a { padding: 10px; text-align: center; font-size: 18px; }
    .sidebar nav a span, .user-info, .logout { display: none; }
    .sidebar-footer { padding: 8px; }
    .content { margin-left: 60px; max-width: calc(100vw - 60px); padding: 16px; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .table { font-size: 12px; }
    .table th, .table td { padding: 8px; }
    .actions { flex-direction: column; }
    .actions .btn { width: 100%; text-align: center; }
}
