/* ============================================
   Najwa — M&M Case Auditor
   ============================================ */

:root {
    --bg-primary: #f8f9fb;
    --bg-card: #ffffff;
    --bg-sidebar: #111827;
    --bg-sidebar-hover: #1f2937;

    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --text-sidebar: #e5e7eb;
    --text-sidebar-muted: #9ca3af;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #eff6ff;
    --accent-border: #bfdbfe;

    --border: #e5e7eb;
    --border-light: #f3f4f6;

    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

    --sidebar-width: 280px;
    --transition: 0.2s ease;
}

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

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    overflow-y: auto;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-header {
    margin-bottom: 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.logo svg {
    color: var(--accent);
}

.sidebar-subtitle {
    font-size: 0.75rem;
    color: var(--text-sidebar-muted);
    margin-top: 4px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.btn-new-case {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px dashed rgba(255,255,255,0.2);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-sidebar);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.btn-new-case:hover {
    background: var(--bg-sidebar-hover);
    border-color: rgba(255,255,255,0.35);
}

.history-section {
    flex: 1;
    margin-top: 24px;
    overflow-y: auto;
}

.sidebar-settings {
    margin-top: 16px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-md);
    background: rgba(255,255,255,0.02);
}

.sidebar-settings .text-input-area {
    margin-bottom: 10px;
}

.sidebar-settings .text-input-area:last-child {
    margin-bottom: 0;
}

.sidebar-settings .input-label {
    color: var(--text-sidebar);
    margin-bottom: 6px;
    font-size: 0.75rem;
}

.sidebar-settings input[type="text"],
.sidebar-settings input[type="password"],
.sidebar-settings select {
    background: #0f172a;
    color: var(--text-sidebar);
    border: 1px solid rgba(255,255,255,0.15);
    padding: 8px 10px;
    font-size: 0.82rem;
}

.sidebar-settings input[type="text"]::placeholder,
.sidebar-settings input[type="password"]::placeholder {
    color: var(--text-sidebar-muted);
}

.history-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-sidebar-muted);
    margin-bottom: 10px;
    font-weight: 600;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-empty {
    font-size: 0.8rem;
    color: var(--text-sidebar-muted);
    padding: 12px;
    text-align: center;
}

.history-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
    font-size: 0.825rem;
    color: var(--text-sidebar);
    line-height: 1.4;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-item:hover {
    background: var(--bg-sidebar-hover);
}

.history-item .history-date {
    font-size: 0.7rem;
    color: var(--text-sidebar-muted);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-info {
    display: flex;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--text-sidebar-muted);
    line-height: 1.5;
}

.sidebar-info svg {
    flex-shrink: 0;
    margin-top: 2px;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.mobile-header {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.mobile-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--border-light);
}

/* ============================================
   Input Section
   ============================================ */
.input-section {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 24px;
    overflow-y: auto;
}

.input-container {
    width: 100%;
    max-width: 720px;
}

.welcome-area {
    text-align: center;
    margin-bottom: 32px;
}

.welcome-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    margin-bottom: 16px;
}

.welcome-area h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-area p {
    font-size: 0.925rem;
    color: var(--text-secondary);
    max-width: 540px;
    margin: 0 auto;
    line-height: 1.65;
}

.input-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

/* Upload Area */
.upload-dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 32px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--bg-primary);
}

.upload-dropzone:hover,
.upload-dropzone.drag-over {
    border-color: var(--accent);
    background: var(--accent-light);
}

.upload-dropzone svg {
    color: var(--text-muted);
    margin-bottom: 10px;
}

.upload-dropzone:hover svg,
.upload-dropzone.drag-over svg {
    color: var(--accent);
}

.upload-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.upload-link {
    color: var(--accent);
    cursor: pointer;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.upload-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.uploaded-file {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--accent-light);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent);
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 0;
}

.file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.file-size {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.btn-remove-file {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: color var(--transition);
}

.btn-remove-file:hover {
    color: var(--danger);
}

/* Divider */
.divider-or {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.divider-or::before,
.divider-or::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* Text Input */
.input-label {
    display: block;
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--text-primary);
    background: var(--bg-primary);
    resize: vertical;
    transition: border-color var(--transition), box-shadow var(--transition);
    min-height: 160px;
}

input[type="text"],
input[type="password"],
select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea::placeholder {
    color: var(--text-muted);
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--border-light);
    border-color: var(--text-muted);
}

.btn-sm {
    padding: 7px 14px;
    font-size: 0.8rem;
}

.input-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}

.btn-submit {
    padding: 12px 28px;
    font-size: 0.925rem;
}

/* ============================================
   Loading Section
   ============================================ */
.loading-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
}

.loading-container {
    text-align: center;
    max-width: 400px;
}

.loading-pulse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    margin-bottom: 20px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.08); opacity: 0.8; }
}

.loading-container h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.loading-status {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.loading-bar {
    width: 100%;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 12px;
}

.loading-bar-fill {
    width: 0%;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    animation: loading-progress 90s ease-out forwards;
}

@keyframes loading-progress {
    0% { width: 0%; }
    10% { width: 15%; }
    30% { width: 40%; }
    50% { width: 60%; }
    70% { width: 75%; }
    90% { width: 88%; }
    100% { width: 95%; }
}

.loading-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ============================================
   Result Section
   ============================================ */
.result-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 32px 24px;
}

.result-container {
    width: 100%;
    max-width: 820px;
    margin: 0 auto;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.result-title-area h2 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.result-timestamp {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.result-actions {
    display: flex;
    gap: 8px;
}

/* Result Markdown */
.result-body {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 36px;
    box-shadow: var(--shadow-sm);
    font-family: 'Source Serif 4', 'Georgia', serif;
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--text-primary);
}

.result-body h1 {
    font-family: 'Inter', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 32px 0 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent);
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.result-body h1:first-child {
    margin-top: 0;
}

.result-body h2 {
    font-family: 'Inter', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    margin: 28px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.result-body h3 {
    font-family: 'Inter', sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    margin: 22px 0 8px;
    color: var(--accent);
}

.result-body h4 {
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    margin: 18px 0 6px;
    color: var(--text-secondary);
}

.result-body p {
    margin: 0 0 14px;
}

.result-body ul, .result-body ol {
    margin: 0 0 14px;
    padding-left: 24px;
}

.result-body li {
    margin-bottom: 6px;
}

.result-body li > ul, .result-body li > ol {
    margin-top: 4px;
    margin-bottom: 4px;
}

.result-body strong {
    font-weight: 600;
    color: var(--text-primary);
}

.result-body em {
    font-style: italic;
}

.result-body blockquote {
    border-left: 3px solid var(--accent);
    margin: 16px 0;
    padding: 10px 16px;
    background: var(--accent-light);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
    font-style: italic;
}

.result-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
}

.result-body th, .result-body td {
    border: 1px solid var(--border);
    padding: 10px 14px;
    text-align: left;
}

.result-body th {
    background: var(--bg-primary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

.result-body tr:nth-child(even) {
    background: var(--bg-primary);
}

.result-body code {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85em;
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.result-body pre {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.result-body pre code {
    background: none;
    border: none;
    padding: 0;
}

.result-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

.result-body a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.result-body a:hover {
    color: var(--accent-hover);
}

/* ============================================
   Error Section
   ============================================ */
.error-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
}

.error-container {
    text-align: center;
    max-width: 440px;
}

.error-container svg {
    color: var(--danger);
    margin-bottom: 16px;
}

.error-container h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.error-message {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.6;
}

/* ============================================
   Sidebar Overlay (Mobile)
   ============================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
}

.sidebar-overlay.active {
    display: block;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .sidebar, .mobile-header, .result-actions, .sidebar-overlay {
        display: none !important;
    }
    .main-content {
        overflow: visible;
    }
    .result-section {
        padding: 0;
    }
    .result-body {
        border: none;
        box-shadow: none;
        padding: 0;
    }
    body {
        overflow: visible;
        height: auto;
    }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }

    .input-section {
        padding: 24px 16px;
    }

    .welcome-area h1 {
        font-size: 1.3rem;
    }

    .input-card {
        padding: 16px;
    }

    .result-section {
        padding: 20px 12px;
    }

    .result-body {
        padding: 20px;
    }

    .result-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .result-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .result-actions .btn {
        flex: 1;
        justify-content: center;
    }
}

/* Scrollbar */
.main-content::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.result-section::-webkit-scrollbar {
    width: 6px;
}

.main-content::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track,
.result-section::-webkit-scrollbar-track {
    background: transparent;
}

.main-content::-webkit-scrollbar-thumb,
.result-section::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
}

/* Copy toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-sidebar);
    color: #fff;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: toast-in 0.3s ease, toast-out 0.3s ease 2s forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(12px); }
}
