/* ===================================================
   ChatMonk.ai – SaaS Design System
   =================================================== */
:root {
    --primary: #FF7A2F;
    /* ChatMonk orange */
    --primary-hover: #e8631a;
    --accent-green: #22C55E;
    --dark-bg: #0D1117;
    /* Dark feature sections */
    --dark-card: #151B23;
    --dark-border: #2A3038;
    --white: #FFFFFF;
    --surface: #F8FAFC;
    --surface2: #F1F5F9;
    --text-dark: #0F172A;
    --text-mid: #374151;
    --text-muted: #64748B;
    --text-light: #94A3B8;
    --border: #E2E8F0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .08);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --font-sans: 'Plus Jakarta Sans', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

/* ── Reset ── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--white);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    cursor: pointer;
    font-family: inherit;
}

/* ── Topnav ── */
.topnav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 64px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topnav-brand {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--text-dark);
}

.topnav-brand span {
    color: var(--primary);
}

.topnav-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #FFF5EE;
    color: var(--primary);
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 99px;
    margin-left: 10px;
    border: 1px solid #FFD4B8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.topnav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topnav-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topnav-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #FF9A60);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.topnav-user .user-details {}

.topnav-user .user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    line-height: 1.2;
}

.topnav-user .user-role {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(255, 122, 47, 0.3);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-dark);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface2);
}

.btn-dark {
    background: var(--dark-bg);
    color: white;
}

.btn-dark:hover {
    background: #1a2130;
}

.btn-ghost {
    background: transparent;
    color: var(--text-mid);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
}

/* ── Page Wrapper ── */
.page-body {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2.5rem 2rem;
}

/* ── Page header bar ── */
.page-heading {
    margin-bottom: 2rem;
}

.page-heading h1 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.page-heading p {
    color: var(--text-muted);
    margin-top: 4px;
    font-size: 15px;
}

/* ── Stats strip ── */
.stats-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 2rem;
}

.stat-pill {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-pill::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.stat-pill .sp-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-pill .sp-value {
    font-size: 30px;
    font-weight: 800;
    color: var(--text-dark);
    margin-top: 4px;
    line-height: 1;
}

.stat-pill .sp-sub {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

/* ── Generator workspace ── */
.workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 3rem;
}

@media (max-width: 850px) {
    .workspace {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.panel-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 6px;
}

.panel-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 1.75rem;
}

/* ── Form elements ── */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label,
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-mid);
    margin-bottom: 7px;
}

.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group textarea,
.form-group select,
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]),
textarea,
select {
    width: 100%;
    padding: 11px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dark);
    font-family: var(--font-sans);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus,
input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 122, 47, 0.12);
    background: var(--white);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.required {
    color: var(--primary);
}

.form-hint {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 5px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 600px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: var(--text-mid);
    cursor: pointer;
    font-size: 14px;
}

.checkbox-group input[type="checkbox"] {
    width: 16px !important;
    height: 16px !important;
    min-width: 16px;
    max-width: 16px;
    accent-color: var(--primary);
    flex-shrink: 0;
    padding: 0 !important;
    background: white;
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    -webkit-appearance: checkbox !important;
    appearance: checkbox !important;
}

/* Generate button */
#btn-generate {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#btn-generate:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(255, 122, 47, 0.3);
}

#btn-generate:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Output panel states ── */
.state-view {
    width: 100%;
}

.state-view:not(.active) {
    display: none;
}

#state-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1rem;
    gap: 10px;
}

.empty-illustration {
    width: 72px;
    height: 72px;
    background: #FFF5EE;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin-bottom: 8px;
}

#state-empty h3 {
    font-size: 18px;
    font-weight: 700;
}

#state-empty p {
    color: var(--text-muted);
    font-size: 14px;
    max-width: 260px;
}

/* progress */
.live-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 1.5rem;
}

.stat-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 800;
    color: var(--text-dark);
    margin-top: 4px;
    font-family: var(--font-mono);
}

.progress-container {
    margin-bottom: 1.5rem;
}

.progress-bar-wrap {
    background: var(--surface2);
    border-radius: 99px;
    height: 8px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #FF9A60);
    border-radius: 99px;
    transition: width 0.5s ease;
}

.progress-text {
    font-size: 13px;
    color: var(--text-muted);
}

.step-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.step {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 14px;
    color: var(--text-muted);
    transition: all 0.3s;
}

.step.active {
    background: #FFF5EE;
    border-color: #FFD4B8;
    color: var(--primary);
    font-weight: 600;
}

.step.done {
    background: #F0FDF4;
    border-color: #BBF7D0;
    color: #16A34A;
}

.step.done::before {
    content: '✓ ';
}

/* complete state */
.success-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.5rem;
}

.success-icon-wrap {
    width: 44px;
    height: 44px;
    background: #F0FDF4;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.success-header h3 {
    font-size: 20px;
    font-weight: 800;
}

.final-stats {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.stat-badge {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 5px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-mid);
}

.download-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.dl-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    background: var(--dark-bg);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: 0.2s;
}

.dl-btn:hover {
    background: #1a2130;
    transform: translateY(-1px);
}

/* email section */
.email-section {
    border-top: 1px solid var(--border);
    padding-top: 1.25rem;
    margin-top: 1.25rem;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 99px;
    cursor: pointer;
    transition: 0.3s;
}

.slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked+.slider {
    background: var(--primary);
}

.toggle-switch input:checked+.slider::before {
    transform: translateX(18px);
}

.toggle-label {
    font-size: 14px;
    font-weight: 500;
}

.email-input-row {
    display: flex;
    gap: 8px;
}

.email-input-row input {
    flex: 1;
}

/* error */
.error-box {
    background: #FEF2F2;
    border: 1px solid #FEE2E2;
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}

.error-box h3 {
    color: #991B1B;
    margin-bottom: 6px;
}

.error-box p {
    color: #B91C1C;
    font-size: 14px;
}

/* ── History section ── */
.history-section {
    margin-top: 1rem;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.history-header h2 {
    font-size: 20px;
    font-weight: 800;
}

.table-wrap {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

th {
    padding: 13px 18px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
}

td {
    padding: 14px 18px;
    font-size: 14px;
    color: var(--text-mid);
    border-bottom: 1px solid var(--border);
}

tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: #FAFBFC;
}

.badge-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
}

.badge-green {
    background: #DCFCE7;
    color: #15803D;
}

.badge-blue {
    background: #DBEAFE;
    color: #1D4ED8;
}

.badge-orange {
    background: #FFF5EE;
    color: var(--primary);
}

/* ── Admin Dashboard ── */
.admin-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: calc(100vh - 64px);
}

.admin-sidebar {
    background: var(--dark-bg);
    padding: 2rem 1.25rem;
    border-right: 1px solid var(--dark-border);
}

.sidebar-logo {
    font-size: 20px;
    font-weight: 800;
    color: white;
    margin-bottom: 2rem;
    display: block;
}

.sidebar-logo span {
    color: var(--primary);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-light);
    font-size: 14px;
    font-weight: 500;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--dark-card);
    color: white;
}

.nav-item.active {
    background: #FF7A2F1A;
    color: var(--primary);
    font-weight: 600;
}

.admin-main-content {
    padding: 2.5rem 2rem;
    background: var(--surface);
}

/* ── Auth pages ── */
.auth-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #FFF8F5 0%, #F0F4FF 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 48px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
    animation: fadeUp 0.5s ease;
}

.auth-card.wide {
    max-width: 500px;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo .brand {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -1px;
}

.auth-logo .brand span {
    color: var(--primary);
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 14px;
    margin-top: 6px;
}

.auth-form .form-group {
    margin-bottom: 16px;
}

.auth-form input {
    background: var(--surface);
    color: var(--text-dark);
    border: 1px solid var(--border);
    padding: 13px 14px;
    border-radius: var(--radius-sm);
}

.auth-form input:focus {
    border-color: var(--primary);
    background: white;
}

.btn-auth {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    transition: 0.2s;
}

.btn-auth:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(255, 122, 47, 0.25);
}

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 14px;
    color: var(--text-muted);
}

.auth-footer a {
    color: var(--primary);
    font-weight: 600;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 18px;
}

.alert-error {
    background: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FEE2E2;
}

.alert-success {
    background: #F0FDF4;
    color: #166534;
    border: 1px solid #DCFCE7;
}

/* ── Loader ── */
.btn-loader {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, .3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Chapter list ── */
.toc-section {
    margin-top: 1.5rem;
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
}

.toc-section h4 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-mid);
}

#final-chapter-list {
    list-style: decimal;
    padding-left: 20px;
}

#final-chapter-list li {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

/* ── Utilities ── */
.text-center {
    text-align: center;
}

.loading-cell {
    color: var(--text-muted);
    font-style: italic;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.gap-2 {
    gap: 0.5rem;
}

/* ── Refresh button ── */
.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: white;
    color: var(--text-muted);
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
}

.btn-icon:hover {
    background: var(--surface);
    color: var(--primary);
    border-color: var(--primary);
}

/* ── email status ── */
#email-status {
    font-size: 13px;
    color: var(--text-muted);
    display: block;
    margin-top: 6px;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.pg-btn {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: white;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-mid);
    text-decoration: none;
    transition: 0.2s;
}

.pg-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.pg-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ── Download links in history table ── */
.dl-link {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--dark-bg);
    color: white;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: 0.2s;
}

.dl-link:hover {
    background: #1a2130;
}

/* ── Avatar ── */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #FF9A60);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}