/* ============================
   DocFlow — Design System
   Mobile-First, Minimalist
   ============================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ---- Variables ---- */
:root {
    --bg: #f8f9fb;
    --bg-card: #ffffff;
    --bg-elevated: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --accent: #f59e0b;
    --accent-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --success: #10b981;
    --success-light: #d1fae5;
    --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 24px rgba(0, 0, 0, 0.12);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-elevated: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --border-light: #1e293b;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #1e3a5f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
}

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

html {
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ---- App Shell ---- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-logo img {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
}

.app-logo h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.app-logo span {
    font-size: 0.65rem;
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

.header-actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.15rem;
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.header-actions button:hover {
    background: var(--border-light);
    color: var(--text);
}

/* ---- Navigation Tabs ---- */
.nav-tabs {
    display: flex;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 12px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex: 1;
    padding: 10px 12px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.tab-btn i {
    font-size: 0.9rem;
}

.tab-btn.active {
    color: var(--primary);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 2.5px;
    background: var(--primary);
    border-radius: 2px 2px 0 0;
}

.tab-btn:hover:not(.active) {
    color: var(--text-secondary);
}

/* ---- Views ---- */
.view {
    padding: 16px;
    max-width: 720px;
    margin: 0 auto;
}

.view.hidden {
    display: none;
}

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

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

.card-title {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.card-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ---- Form Elements ---- */
.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 0.85rem;
    color: var(--text);
    background: var(--bg-card);
    transition: var(--transition);
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    min-height: 80px;
    resize: vertical;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-md);
}

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

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

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.75rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

/* ---- Template Grid ---- */
.template-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.template-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

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

.template-card.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.template-card .template-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    font-size: 1rem;
}

.template-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.template-card p {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.template-card .badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--success-light);
    color: var(--success);
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 20px;
    text-transform: uppercase;
}

/* ---- Items Table ---- */
.items-table-wrapper {
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.items-table th {
    background: var(--border-light);
    padding: 8px 10px;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.items-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.items-table tr:last-child td {
    border-bottom: none;
}

.items-table input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.8rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: var(--transition);
}

.items-table input:focus {
    border-color: var(--primary);
}

.items-table input[type="number"] {
    width: 70px;
}

/* ---- Preview Section ---- */
.preview-grid {
    display: grid;
    gap: 12px;
}

.preview-grid[data-count="1"] {
    grid-template-columns: 1fr;
}

.preview-grid[data-count="2"] {
    grid-template-columns: 1fr 1fr;
}

.preview-grid[data-count="3"] {
    grid-template-columns: 1fr 1fr;
}

.preview-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
}

.preview-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.preview-card-header {
    padding: 8px 12px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.preview-card-body {
    position: relative;
    padding: 8px;
    height: 200px;
    overflow: hidden;
}

.preview-card-body iframe {
    width: 210mm;
    height: 297mm;
    border: none;
    transform-origin: top left;
    pointer-events: none;
}

/* ---- Client List ---- */
.client-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.client-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.client-item:hover {
    border-color: var(--primary);
}

.client-item-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.client-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
}

.client-item h4 {
    font-size: 0.82rem;
    font-weight: 600;
}

.client-item p {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.client-item-actions {
    display: flex;
    gap: 4px;
}

/* ---- Action Bar (Sticky Bottom) ---- */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 90;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 10px 16px;
    display: flex;
    gap: 8px;
    justify-content: center;
    max-width: 720px;
    margin: 0 auto;
}

.action-bar .btn {
    flex: 1;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 0.75rem;
}

/* ---- Modal ---- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 20px;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.modal-close {
    width: 30px;
    height: 30px;
    border: none;
    background: var(--border-light);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--danger-light);
    color: var(--danger);
}

/* ---- Utilities ---- */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.gap-2 {
    gap: 8px;
}

.gap-3 {
    gap: 12px;
}

.mt-2 {
    margin-top: 8px;
}

.mt-3 {
    margin-top: 12px;
}

.mb-2 {
    margin-bottom: 8px;
}

.mb-3 {
    margin-bottom: 12px;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-sm {
    font-size: 0.75rem;
}

.text-muted {
    color: var(--text-muted);
}

.fw-600 {
    font-weight: 600;
}

/* ---- Section Headers ---- */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h2 {
    font-size: 0.9rem;
    font-weight: 700;
}

/* ---- Responsive ---- */
@media (min-width: 640px) {
    .template-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }

    .view {
        padding: 24px;
    }

    .preview-card-body {
        height: 260px;
    }
}

/* ---- Custom Alert ---- */
.custom-alert {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 10px 20px;
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

/* Body padding to account for action bar */
body {
    padding-bottom: 70px;
}