/* ============================================
   CCL Tool - Main Stylesheet
   ============================================ */

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

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --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;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-800);
    background: var(--gray-50);
}

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

h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 1rem; }
h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.75rem; }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.5rem; }

/* --- Navigation --- */
.main-nav {
    display: flex;
    align-items: center;
    background: var(--gray-800);
    color: white;
    padding: 0 1.5rem;
    height: 56px;
    gap: 2rem;
}

.nav-brand {
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.nav-links a {
    color: var(--gray-300);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: background 0.15s, color 0.15s;
}
.nav-links a:hover,
.nav-links a.active {
    background: rgba(255,255,255,0.1);
    color: white;
    text-decoration: none;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.user-name {
    font-size: 0.875rem;
    color: var(--gray-300);
}

/* --- Container --- */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { text-decoration: none; }

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

.btn-success {
    background: var(--success);
    color: white;
}
.btn-success:hover { background: #15803d; }

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #b91c1c; }

.btn-outline {
    background: transparent;
    color: white;
    border-color: var(--gray-400);
}
.btn-outline:hover {
    background: rgba(255,255,255,0.1);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
    border-color: var(--gray-300);
}
.btn-secondary:hover { background: var(--gray-300); }

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8rem;
}

.btn-full { width: 100%; justify-content: center; }

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    color: var(--gray-700);
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    background: white;
    transition: border-color 0.15s;
}
.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-group textarea {
    min-height: 100px;
    resize: vertical;
}
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}
.form-inline {
    display: flex;
    align-items: end;
    gap: 0.75rem;
}
.form-help {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

/* --- Alerts --- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.875rem;
}
.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
}
.alert-close:hover { opacity: 1; }

/* --- Tables --- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.table th, .table td {
    padding: 0.625rem 0.875rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.875rem;
}
.table th {
    background: var(--gray-100);
    font-weight: 600;
    color: var(--gray-600);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-50); }

/* --- Cards --- */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    border: 1px solid var(--gray-200);
}
.card-action {
    display: block;
    color: inherit;
    transition: box-shadow 0.15s, border-color 0.15s;
}
.card-action:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    text-decoration: none;
}
.card-action .card-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}
.card-action h2 {
    color: var(--primary);
    margin-bottom: 0.25rem;
}
.card-action p {
    color: var(--gray-500);
    font-size: 0.875rem;
}

/* --- Dashboard --- */
.dashboard-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.dashboard-summary {
    margin-top: 1rem;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-green { background: var(--success-light); color: var(--success); }

/* --- Tabs --- */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 1rem;
    gap: 0;
    overflow-x: auto;
}
.tab {
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}
.tab:hover {
    color: var(--gray-700);
}
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-panel {
    display: none;
}
.tab-panel.active {
    display: block;
}

/* --- Login --- */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--gray-100);
}
.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
}
.login-card h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--gray-800);
}
.login-form .form-group {
    margin-bottom: 1.25rem;
}

/* --- Two-column letter layout --- */
.letter-layout {
    display: grid;
    grid-template-columns: 45% 55%;
    gap: 1.5rem;
    min-height: calc(100vh - 140px);
}
.letter-preview {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
}
.letter-preview.collapsed {
    display: none;
}
.letter-form {
    min-width: 0;
}

/* Preview content styling */
.preview-content {
    font-family: 'DejaVu Sans', Arial, sans-serif;
    font-size: 11pt;
    line-height: 1.5;
    color: #333;
}
.preview-content h2 {
    font-size: 14pt;
    color: #222;
    margin-top: 20px;
    margin-bottom: 10px;
    border-bottom: 1px solid #ccc;
    padding-bottom: 5px;
}
.preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
}
.preview-content th,
.preview-content td {
    border: 1px solid #999;
    padding: 6px 10px;
    text-align: left;
}
.preview-content th {
    background: #f0f0f0;
    font-weight: bold;
}

/* Variable highlighting in preview */
.var-unfilled {
    background: #fef3c7;
    color: #dc2626;
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 600;
}

/* Page break indicator */
.page-break-indicator {
    border-top: 2px dashed var(--gray-300);
    margin: 1rem 0;
    position: relative;
    padding-top: 0.25rem;
}
.page-break-indicator::after {
    content: 'Page break';
    position: absolute;
    top: -0.5rem;
    right: 0;
    font-size: 0.7rem;
    color: var(--gray-400);
    background: white;
    padding: 0 0.5rem;
}

/* --- Schedule builder --- */
.schedule-builder {
    margin-top: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    background: var(--gray-50);
}
.schedule-builder h3 {
    margin-bottom: 0.75rem;
}
.schedule-row {
    display: grid;
    grid-template-columns: 140px 100px 100px 1fr 40px;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}
.schedule-row input {
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
}
.schedule-row .btn-remove {
    padding: 0.25rem;
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1.1rem;
}

/* --- Bottom action bar --- */
.action-bar {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid var(--gray-200);
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0 -2px 4px rgba(0,0,0,0.05);
    z-index: 10;
}

/* --- Version history sidebar --- */
.version-list {
    margin-top: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    max-height: 300px;
    overflow-y: auto;
}
.version-item {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.8rem;
}
.version-item:last-child { border-bottom: none; }
.version-item .version-meta {
    color: var(--gray-500);
}

/* --- Utility --- */
.text-muted { color: var(--gray-400); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }

/* --- Keyboard shortcut hints --- */
.shortcut-hint {
    font-size: 0.7rem;
    color: var(--gray-400);
    margin-left: 0.25rem;
}

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active {
    display: flex;
}
.modal {
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 1.5rem;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h2 {
    margin-bottom: 1rem;
}
.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* --- Print preview --- */
@media print {
    .main-nav, .action-bar, .letter-form, .btn, .alert { display: none !important; }
    .letter-layout { grid-template-columns: 1fr; }
    .letter-preview {
        position: static;
        max-height: none;
        border: none;
        box-shadow: none;
        padding: 0;
    }
    body { background: white; }
    .container { max-width: none; padding: 0; }
}
