/* ========================================
   Consent Forms App - Styles
   ======================================== */

:root {
    --app-bg: #f8f9fa;
    --app-white: #ffffff;
    --app-black: #26060C;
    --app-gray-50: #f9fafb;
    --app-gray-100: #f3f4f6;
    --app-gray-200: #e5e7eb;
    --app-gray-300: #d1d5db;
    --app-gray-400: #9ca3af;
    --app-gray-500: #6b7280;
    --app-gray-600: #4b5563;
    --app-gray-700: #374151;
    --app-gray-800: #1f2937;
    --app-gray-900: #111827;
    --app-teal: #73102A;
    --app-teal-dark: #590E1C;
    --app-teal-light: #f5e6ea;
    --app-red: #ef4444;
    --app-red-light: #fef2f2;
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --transition: 150ms ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--app-bg);
    color: var(--app-gray-800);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--app-teal); text-decoration: none; }
a:hover { color: var(--app-teal-dark); }

/* ─── Auth Pages ─── */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background: var(--app-gray-900);
}

.auth-container { width: 100%; max-width: 420px; }

.auth-card {
    background: var(--app-white);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}

.auth-brand {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-family: 'Manrope', sans-serif;
    font-weight: 800;
}

.brand-text { color: #fff; }
.sidebar .brand-text { color: #fff; }
.brand-accent { color: var(--app-teal); }

.auth-title {
    font-family: 'Manrope', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    color: var(--app-gray-500);
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

.auth-form .btn { margin-top: 0.5rem; }

.auth-footer {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--app-gray-500);
}

.auth-footer a { font-weight: 500; }

.auth-forgot {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--app-gray-400);
}

.auth-terms {
    font-size: 0.75rem;
    color: var(--app-gray-400);
    text-align: center;
    line-height: 1.4;
}

.auth-back {
    text-align: center;
    margin-top: 1.5rem;
}

.auth-back a {
    color: var(--app-gray-400);
    font-size: 0.875rem;
}

.auth-back a:hover { color: var(--app-white); }

/* ─── Form Elements ─── */
.form-group { display: flex; flex-direction: column; gap: 0.375rem; }

.form-group label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--app-gray-700);
}

.form-group .required { color: var(--app-red); }

.form-group input,
.form-group textarea,
.form-group select {
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--app-gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--app-gray-800);
    background: var(--app-white);
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--app-teal);
    box-shadow: 0 0 0 3px rgba(115, 16, 42, 0.15);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--app-gray-400);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.input-readonly {
    background: var(--app-gray-50) !important;
    color: var(--app-gray-500) !important;
    cursor: not-allowed;
}

/* ─── Alert ─── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: var(--app-red-light);
    color: var(--app-red);
    border: 1px solid #fecaca;
}

.alert-success {
    background: var(--app-teal-light);
    color: var(--app-teal-dark);
    border: 1px solid #a7f3d0;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

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

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

.btn-outline {
    background: transparent;
    border-color: var(--app-gray-300);
    color: var(--app-gray-700);
}

.btn-outline:hover {
    background: var(--app-gray-50);
    border-color: var(--app-gray-400);
    color: var(--app-gray-700);
}

.btn-ghost {
    background: transparent;
    color: var(--app-gray-600);
    padding: 0.5rem 0.75rem;
}

.btn-ghost:hover {
    background: var(--app-gray-100);
    color: var(--app-gray-800);
}

.btn-danger {
    background: transparent;
    border-color: var(--app-gray-300);
    color: var(--app-red);
}

.btn-danger:hover {
    background: var(--app-red-light);
    border-color: var(--app-red);
}

.btn-block { width: 100%; }

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* ─── App Layout ─── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ─── */
.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--app-gray-900);
    color: white;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand a {
    font-family: 'Manrope', sans-serif;
    font-size: 1.25rem;
    font-weight: 800;
    color: white;
    text-decoration: none;
}

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

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius);
    color: var(--app-gray-400);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    text-decoration: none;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.06);
    color: white;
}

.sidebar-link.active {
    background: rgba(115, 16, 42, 0.15);
    color: var(--app-teal);
}

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

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--app-teal);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.6875rem;
    color: var(--app-gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-link { color: var(--app-gray-500) !important; }
.logout-link:hover { color: var(--app-red) !important; background: rgba(239,68,68,0.1) !important; }

/* ─── Mobile Top Bar ─── */
.app-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: var(--app-gray-900);
    color: white;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 99;
}

.topbar-brand {
    font-family: 'Manrope', sans-serif;
    font-size: 1.125rem;
    font-weight: 800;
    color: white;
}

.topbar-brand:hover { color: white; }

.topbar-logout { color: var(--app-gray-400); }
.topbar-logout:hover { color: var(--app-red); }

.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 4px;
}

.sidebar-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: white;
    border-radius: 1px;
    transition: all 0.3s ease;
}

/* ─── Main Content ─── */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem;
    min-height: 100vh;
}

/* ─── Page Header ─── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 1rem;
}

.page-header h1 {
    font-family: 'Manrope', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--app-gray-900);
}

.page-subtitle {
    color: var(--app-gray-500);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ─── Empty State ─── */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background: var(--app-white);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--app-gray-200);
}

.empty-icon {
    color: var(--app-gray-300);
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-family: 'Manrope', sans-serif;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--app-gray-700);
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--app-gray-500);
    font-size: 0.875rem;
}

/* ─── Forms Grid ─── */
.forms-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
    margin-bottom: 3rem;
}

.form-card {
    background: var(--app-white);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--app-gray-200);
    transition: box-shadow var(--transition);
}

.form-card:hover { box-shadow: var(--shadow); }

.form-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.form-card-title {
    font-family: 'Manrope', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--app-gray-900);
}

.form-card-badge {
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    background: var(--app-teal-light);
    color: var(--app-teal-dark);
    border-radius: 99px;
    white-space: nowrap;
}

.form-card-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8125rem;
    color: var(--app-gray-500);
    margin-bottom: 1rem;
}

.form-card-actions {
    display: flex;
    gap: 0.5rem;
}

/* ─── Templates Section ─── */
.templates-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--app-gray-200);
}

.section-header {
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-family: 'Manrope', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--app-gray-900);
}

.section-header p {
    color: var(--app-gray-500);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.template-card {
    background: var(--app-white);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    border: 1px solid var(--app-gray-200);
    transition: all var(--transition);
}

.template-card:hover {
    border-color: var(--app-teal);
    box-shadow: var(--shadow);
}

.template-card-category {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--app-teal);
    margin-bottom: 0.5rem;
}

.template-card-title {
    font-family: 'Manrope', sans-serif;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--app-gray-900);
    margin-bottom: 0.5rem;
}

.template-card-desc {
    font-size: 0.8125rem;
    color: var(--app-gray-500);
    line-height: 1.5;
    margin-bottom: 1rem;
}

/* ─── Editor ─── */
.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 0 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--app-gray-200);
    flex-wrap: wrap;
}

.editor-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.editor-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.editor-title-input {
    border: none;
    background: transparent;
    font-family: 'Manrope', sans-serif;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--app-gray-900);
    padding: 0.25rem 0;
    flex: 1;
    min-width: 200px;
}

.editor-title-input:focus {
    outline: none;
    border-bottom: 2px solid var(--app-teal);
}

.save-status {
    font-size: 0.75rem;
    color: var(--app-gray-400);
    white-space: nowrap;
}

.save-status.saved { color: var(--app-teal); }
.save-status.saving { color: var(--app-gray-400); }
.save-status.error { color: var(--app-red); }

.editor-container {
    background: var(--app-white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--app-gray-200);
}

/* TinyMCE iframe styles */
.tox-tinymce { border: none !important; border-radius: var(--radius-lg) !important; }
.tox .tox-toolbar__group { border-color: var(--app-gray-200) !important; }

/* ─── Modal ─── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--app-white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-large { max-width: 900px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--app-gray-200);
}

.modal-header h3 {
    font-family: 'Manrope', sans-serif;
    font-weight: 700;
    font-size: 1.125rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--app-gray-400);
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.modal-close:hover { color: var(--app-gray-700); }

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--app-gray-200);
}

.preview-content {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    max-width: 800px;
    margin: 0 auto;
}

.preview-content h1, .preview-content h2, .preview-content h3 {
    font-family: 'Manrope', sans-serif;
}

.preview-content table {
    width: 100%;
    border-collapse: collapse;
}

.preview-content td, .preview-content th {
    border: 1px solid #ddd;
    padding: 8px;
}

/* ─── Settings ─── */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    max-width: 700px;
}

.settings-card {
    background: var(--app-white);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--app-gray-200);
}

.settings-card-title {
    font-family: 'Manrope', sans-serif;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--app-gray-900);
    margin-bottom: 0.25rem;
}

.settings-card-desc {
    font-size: 0.8125rem;
    color: var(--app-gray-500);
    margin-bottom: 1.25rem;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.settings-divider {
    border: none;
    border-top: 1px solid var(--app-gray-200);
    margin: 1.5rem 0;
}

.settings-subheading {
    font-family: 'Manrope', sans-serif;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--app-gray-800);
    margin-bottom: 0.5rem;
}

.settings-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    max-width: 700px;
}

/* Logo upload */
.logo-upload-area {
    cursor: pointer;
}

.logo-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem;
    border: 2px dashed var(--app-gray-300);
    border-radius: var(--radius);
    color: var(--app-gray-400);
    font-size: 0.8125rem;
    transition: all var(--transition);
}

.logo-placeholder:hover {
    border-color: var(--app-teal);
    color: var(--app-teal);
}

.logo-preview {
    position: relative;
    display: inline-block;
}

.logo-preview img {
    max-height: 80px;
    max-width: 250px;
    border-radius: var(--radius);
    border: 1px solid var(--app-gray-200);
    padding: 0.5rem;
}

.logo-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--app-red);
    color: white;
    border: 2px solid white;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.color-picker-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-picker-group input[type="color"] {
    width: 42px;
    height: 42px;
    border: 1px solid var(--app-gray-300);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 2px;
}

.color-hex-input {
    width: 100px;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--app-gray-300);
    border-radius: var(--radius);
    font-family: monospace;
    font-size: 0.875rem;
}

/* ─── Toast ─── */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    color: white;
    background: var(--app-gray-800);
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 300;
    pointer-events: none;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success { background: var(--app-teal); }
.toast.error { background: var(--app-red); }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

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

    .app-topbar { display: flex; }

    .app-main {
        margin-left: 0;
        padding-top: calc(var(--topbar-height) + 1.5rem);
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
    }

    .forms-grid {
        grid-template-columns: 1fr;
    }

    .templates-grid {
        grid-template-columns: 1fr;
    }

    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .editor-toolbar-right {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .modal-content {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
    }
}

@media (max-width: 480px) {
    .auth-card { padding: 1.5rem; }

    .app-main { padding: 1rem; padding-top: calc(var(--topbar-height) + 1rem); }

    .form-card-actions {
        flex-wrap: wrap;
    }
}

/* ─── Sidebar overlay for mobile ─── */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

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