/* ============================================
   DualDoc — Main Stylesheet
   Font: Playfair Display + Lato
   ============================================ */

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

:root {
    --ink:        #1a1a2e;
    --ink-light:  #4a4a6a;
    --ink-faint:  #8888aa;
    --paper:      #fafaf7;
    --paper-warm: #f4f3ee;
    --paper-mid:  #ebebE3;
    --gold:       #c8973a;
    --gold-light: #e8b96a;
    --red:        #c0392b;
    --green:      #27664a;
    --panel-l:    #f7f6f0;
    --panel-r:    #f0f4f7;
    --border:     #ddddd0;
    --shadow:     0 2px 12px rgba(26,26,46,0.08);
    --shadow-lg:  0 8px 32px rgba(26,26,46,0.14);
    --radius:     6px;
    --nav-h:      56px;
    --font-serif: 'Playfair Display', Georgia, serif;
    --font-sans:  'Lato', system-ui, sans-serif;
}

html, body {
    height: 100%;
    font-family: var(--font-sans);
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.6;
}

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

/* ============================================
   NAVBAR
   ============================================ */
.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: var(--ink);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.nav-brand {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--gold) !important;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0.02em;
}

.brand-icon {
    font-size: 1rem;
    opacity: 0.7;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-user {
    color: var(--ink-faint);
    font-size: 0.85rem;
}

.nav-link {
    color: rgba(255,255,255,0.75);
    font-size: 0.875rem;
    text-decoration: none;
    transition: color 0.15s;
}
.nav-link:hover { color: #fff; text-decoration: none; }

.nav-btn-logout {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.65);
    padding: 5px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-sans);
}
.nav-btn-logout:hover {
    border-color: rgba(255,255,255,0.5);
    color: #fff;
}

/* ============================================
   MAIN WRAP
   ============================================ */
.main-wrap {
    margin-top: var(--nav-h);
    min-height: calc(100vh - var(--nav-h));
    padding: 40px 24px;
}

/* ============================================
   AUTH PAGES
   ============================================ */
.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--nav-h));
    padding: 40px 16px;
}

.auth-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    padding: 48px 44px;
    width: 100%;
    max-width: 420px;
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    font-size: 2rem;
    margin-bottom: 10px;
    opacity: 0.5;
}

.auth-title {
    font-family: var(--font-serif);
    font-size: 2rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: 0.02em;
}

.auth-subtitle {
    color: var(--ink-faint);
    font-size: 0.9rem;
    margin-top: 4px;
}

.auth-form { display: flex; flex-direction: column; gap: 18px; }

.auth-switch {
    text-align: center;
    margin-top: 24px;
    font-size: 0.875rem;
    color: var(--ink-light);
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-light);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="url"] {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    color: var(--ink);
    background: var(--paper);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-group input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(200,151,58,0.12);
}

.form-hint {
    font-size: 0.78rem;
    color: var(--ink-faint);
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--ink-light);
}

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

/* ============================================
   BUTTONS
   ============================================ */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 11px 22px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
    letter-spacing: 0.02em;
}
.btn-primary:hover {
    background: #2d2d50;
    text-decoration: none;
    color: #fff;
}
.btn-primary:active { transform: scale(0.98); }

.btn-full { width: 100%; }

.btn-ghost {
    display: inline-flex;
    align-items: center;
    background: transparent;
    color: var(--ink-light);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 20px;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}
.btn-ghost:hover { border-color: var(--ink-light); color: var(--ink); text-decoration: none; }

.btn-danger-sm {
    background: transparent;
    color: var(--red);
    border: 1px solid rgba(192,57,43,0.3);
    border-radius: var(--radius);
    padding: 5px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: all 0.15s;
}
.btn-danger-sm:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ============================================
   ALERTS
   ============================================ */
.alert {
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 0.875rem;
    margin-bottom: 20px;
}
.alert p { margin: 0; }
.alert-error  { background: #fdf2f2; border: 1px solid #f5c6cb; color: #721c24; }
.alert-success { background: #f0faf4; border: 1px solid #b7dfca; color: #155724; }

/* ============================================
   PAGE LAYOUT
   ============================================ */
.page-wrap {
    max-width: 1100px;
    margin: 0 auto;
}

.page-wrap-narrow {
    max-width: 640px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 36px;
    gap: 16px;
}

.page-title {
    font-family: var(--font-serif);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}

.page-sub {
    color: var(--ink-faint);
    font-size: 0.875rem;
    margin-top: 4px;
}

/* ============================================
   DOCUMENT GRID
   ============================================ */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.doc-card {
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 22px 24px;
    text-decoration: none;
    color: var(--ink);
    display: block;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.doc-card:hover {
    border-color: var(--gold);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
    text-decoration: none;
    color: var(--ink);
}

.doc-card-labels {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.doc-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gold);
}

.doc-divider { color: var(--border); font-size: 0.8rem; }

.doc-card-title {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
    line-height: 1.3;
}

.doc-card-meta {
    font-size: 0.78rem;
    color: var(--ink-faint);
    margin-bottom: 14px;
}

.doc-card-preview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.preview-pane {
    background: var(--paper-warm);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 0.75rem;
    color: var(--ink-light);
    line-height: 1.5;
    min-height: 48px;
    overflow: hidden;
}

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--ink-light);
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-family: var(--font-serif); font-size: 1.4rem; margin-bottom: 8px; color: var(--ink); }
.empty-state p { color: var(--ink-faint); margin-bottom: 24px; }

/* ============================================
   CREATE FORM
   ============================================ */
.create-form {
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 36px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ============================================
   EDITOR LAYOUT
   ============================================ */
.editor-wrap {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.editor-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 50px;
    background: var(--paper-warm);
    border-bottom: 1.5px solid var(--border);
    flex-shrink: 0;
    gap: 16px;
}

.editor-topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 0;
}

.back-link {
    color: var(--ink-faint);
    font-size: 0.8rem;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s;
}
.back-link:hover { color: var(--gold); text-decoration: none; }

.doc-title-wrap { flex: 1; min-width: 0; }

.doc-title-input {
    border: none;
    background: transparent;
    font-family: var(--font-serif);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--ink);
    width: 100%;
    outline: none;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background 0.15s;
}
.doc-title-input:hover { background: var(--paper-mid); }
.doc-title-input:focus { background: #fff; box-shadow: 0 0 0 2px var(--gold); }

.editor-topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.save-status {
    font-size: 0.78rem;
    color: var(--ink-faint);
    transition: color 0.2s;
}
.save-status.saving { color: var(--gold); }
.save-status.saved  { color: var(--green); }
.save-status.error  { color: var(--red); }

/* ============================================
   PANELS
   ============================================ */
.panels {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - var(--nav-h) - 50px - 50px);
}

.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.panel-left  { background: var(--panel-l); }
.panel-right { background: var(--panel-r); }

.panel-divider {
    width: 3px;
    background: var(--border);
    flex-shrink: 0;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1.5px solid var(--border);
    background: rgba(255,255,255,0.6);
    flex-shrink: 0;
    gap: 12px;
    flex-wrap: wrap;
}

.panel-label-input {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--gold);
    border: none;
    background: transparent;
    outline: none;
    padding: 2px 4px;
    border-radius: 3px;
    min-width: 80px;
    max-width: 160px;
    transition: background 0.15s;
}
.panel-label-input:hover { background: rgba(200,151,58,0.08); }
.panel-label-input:focus { background: rgba(200,151,58,0.12); box-shadow: 0 0 0 2px rgba(200,151,58,0.3); }

/* ============================================
   TOOLBAR
   ============================================ */
.toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
}

.tb-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--ink-light);
    font-family: var(--font-sans);
    line-height: 1;
    transition: all 0.12s;
    min-width: 28px;
    text-align: center;
}
.tb-btn:hover {
    background: rgba(26,26,46,0.07);
    border-color: var(--border);
    color: var(--ink);
}
.tb-btn:active { background: rgba(26,26,46,0.14); }
.tb-btn.tb-sep { margin-left: 6px; }

/* ============================================
   EDITOR BODY (contenteditable)
   ============================================ */
.editor-body {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
    outline: none;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--ink);
    caret-color: var(--gold);
}

.editor-body:empty::before {
    content: attr(data-side) == 'left' ? 'Start typing your notes and edits...' : 'Start typing your document...';
    color: var(--ink-faint);
    pointer-events: none;
}

.editor-body[data-side="left"]:empty::before {
    content: 'Start typing your notes and edits...';
    color: var(--ink-faint);
    pointer-events: none;
    font-style: italic;
}

.editor-body[data-side="right"]:empty::before {
    content: 'Start typing your document here...';
    color: var(--ink-faint);
    pointer-events: none;
    font-style: italic;
}

.editor-body a {
    color: var(--gold);
    text-decoration: underline;
}

.editor-body ul, .editor-body ol {
    padding-left: 1.5em;
    margin: 0.4em 0;
}

.editor-body li { margin: 0.2em 0; }

.editor-body b, .editor-body strong { font-weight: 700; }
.editor-body i, .editor-body em { font-style: italic; }
.editor-body u { text-decoration: underline; }

/* Scrollbar styling */
.editor-body::-webkit-scrollbar { width: 6px; }
.editor-body::-webkit-scrollbar-track { background: transparent; }
.editor-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.editor-body::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* ============================================
   LINK MODAL
   ============================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(26,26,46,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    backdrop-filter: blur(2px);
}

.modal-box {
    background: #fff;
    border-radius: 10px;
    padding: 32px 36px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-title {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--ink);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 700px) {
    .panels { flex-direction: column; }
    .panel-divider { width: 100%; height: 3px; }
    .panels { height: auto; overflow: auto; }
    .panel { height: 50vh; }
    .form-row { grid-template-columns: 1fr; }
    .auth-card { padding: 32px 24px; }
    .create-form { padding: 24px 20px; }
    .editor-topbar { padding: 0 12px; }
    .editor-body { padding: 16px 18px; }
}
