/* ============================================================
   Transcriber - Main Stylesheet
   Mobile-first responsive design
   ============================================================ */

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

:root {
    --color-bg:         #f5f5f7;
    --color-surface:    #ffffff;
    --color-text:       #1d1d1f;
    --color-text-muted: #6e6e73;
    --color-primary:    #0071e3;
    --color-primary-hover: #0077ed;
    --color-success:    #34c759;
    --color-danger:     #ff3b30;
    --color-warning:    #ff9500;
    --color-border:     #d2d2d7;
    --color-header-bg:  #1a1a2e;
    --color-header-text:#ffffff;
    --radius:           8px;
    --radius-lg:        12px;
    --shadow:           0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg:        0 4px 12px rgba(0,0,0,0.15);
    --transition:       0.2s ease;
}

[x-cloak] {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-success {
    background: var(--color-success);
    color: white;
}
.btn-success:hover:not(:disabled) {
    background: #2db84d;
}

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

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}
.btn-ghost:hover {
    background: rgba(0,0,0,0.05);
    color: var(--color-text);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 17px;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: rgba(255,255,255,0.8);
    cursor: pointer;
    font-size: 14px;
    transition: background var(--transition);
}
.btn-icon:hover { background: rgba(255,255,255,1); }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-icon-danger:hover { background: var(--color-danger); color: white; }

/* ---- Forms ---- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 16px;
    font-family: inherit;
    transition: border-color var(--transition);
    background: var(--color-surface);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0,113,227,0.15);
}

/* ---- Alerts ---- */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 16px;
}

.alert-error {
    background: #fff2f0;
    color: var(--color-danger);
    border: 1px solid #ffccc7;
}

.alert-success {
    background: #f0fff4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

/* ---- Status Badges ---- */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-pending {
    background: #fff7e6;
    color: var(--color-warning);
}

.status-processing {
    background: #e6f7ff;
    color: var(--color-primary);
    animation: pulse 2s infinite;
}

.status-complete {
    background: #f0fff4;
    color: var(--color-success);
}

.status-error {
    background: #fff2f0;
    color: var(--color-danger);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 14px;
    margin-bottom: 32px;
}

/* ============================================================
   APP HEADER
   ============================================================ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--color-header-bg);
    color: var(--color-header-text);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-title {
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-right .btn-ghost {
    color: rgba(255,255,255,0.7);
}
.header-right .btn-ghost:hover {
    color: white;
    background: rgba(255,255,255,0.1);
}

.user-name {
    font-size: 14px;
    color: rgba(255,255,255,0.7);
}

/* ---- Toast Notifications ---- */
.toast-container {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
}

.toast {
    padding: 12px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    font-size: 14px;
    max-width: 90vw;
}

.toast-info    { background: var(--color-primary); color: white; }
.toast-warning { background: var(--color-warning); color: white; }
.toast-error   { background: var(--color-danger); color: white; }
.toast-success { background: var(--color-success); color: white; }

/* ============================================================
   VIEW HEADER
   ============================================================ */
.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    gap: 16px;
}

.view-header h2 {
    font-size: 22px;
    font-weight: 600;
}

/* ============================================================
   DOCUMENT LIST
   ============================================================ */
.loading-state,
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}

.empty-state p {
    margin-bottom: 8px;
}

.document-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 0 20px 20px;
}

.document-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: box-shadow var(--transition), transform var(--transition);
}

.document-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    word-break: break-word;
}

.card-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

.card-actions {
    display: flex;
    justify-content: flex-end;
}

/* ============================================================
   CAPTURE VIEW
   ============================================================ */
.capture-view {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 56px);
    padding: 20px;
}

.capture-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.title-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 16px;
    font-family: inherit;
}

.title-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.page-strip {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 12px 0;
    margin-bottom: 20px;
    -webkit-overflow-scrolling: touch;
}

.page-thumb {
    position: relative;
    flex-shrink: 0;
    width: 120px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    background: var(--color-surface);
}

.page-thumb img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}

.page-number {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(0,0,0,0.7);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.thumb-controls {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 6px;
}

.capture-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--color-text-muted);
    padding: 40px;
}

.capture-actions {
    display: flex;
    gap: 12px;
    margin-top: auto;
    padding-top: 20px;
}

.capture-actions .btn {
    flex: 1;
}

/* Upload Progress */
.upload-progress {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.progress-bar {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: var(--color-border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 16px;
}

.progress-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.upload-status {
    color: var(--color-text-muted);
    font-size: 14px;
    text-align: center;
}

/* ============================================================
   DOCUMENT VIEWER
   ============================================================ */
.viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 56px;
    z-index: 50;
    gap: 12px;
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.viewer-title {
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.title-edit-input {
    font-size: 18px;
    font-weight: 600;
    padding: 4px 8px;
    border: 2px solid var(--color-primary);
    border-radius: 4px;
    width: 300px;
    max-width: 100%;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.toolbar-control {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--color-text-muted);
    cursor: pointer;
}

.opacity-slider {
    width: 80px;
}

.viewer-pages {
    padding: 20px;
    max-width: 900px;
    margin: 0 auto;
}

.viewer-page {
    margin-bottom: 32px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.page-status-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: #fafafa;
}

.page-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: white;
}

.page-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 0;
    pointer-events: none;
}

/* Hidden on screen, shown only in print */
.print-only-image {
    display: none;
}

.text-region {
    z-index: 1;
    overflow: hidden;
    cursor: default;
    transition: background var(--transition);
}

.text-region:hover {
    background: rgba(0, 113, 227, 0.08);
}

.region-text {
    display: block;
    font-size: 14px;
    line-height: 1.4;
    color: var(--color-text);
    white-space: pre-wrap;
    word-break: break-word;
    padding: 2px 4px;
}

.region-editor {
    width: 100%;
    height: 100%;
    min-height: 60px;
    padding: 4px;
    border: 2px solid var(--color-primary);
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    resize: vertical;
    background: rgba(255, 255, 255, 0.95);
}

.page-label {
    padding: 8px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--color-text-muted);
    border-top: 1px solid var(--color-border);
}

/* ============================================================
   ADMIN VIEW
   ============================================================ */
.admin-card {
    max-width: 500px;
    margin: 0 auto;
    padding: 0 20px;
}

.register-form {
    background: var(--color-surface);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

/* ============================================================
   DESKTOP BREAKPOINT (>= 768px)
   ============================================================ */
@media (min-width: 768px) {
    .document-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .capture-view {
        max-width: 700px;
        margin: 0 auto;
    }

    .page-thumb {
        width: 150px;
    }

    .page-thumb img {
        height: 200px;
    }
}

@media (min-width: 1024px) {
    .document-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
