/* =============================================================================
   Docal — Main Stylesheet
   ============================================================================= */

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

:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #EEF2FF;
    --success: #059669;
    --success-hover: #047857;
    --success-light: #ECFDF5;
    --danger: #DC2626;
    --danger-hover: #B91C1C;
    --danger-light: #FEF2F2;
    --warning: #D97706;
    --warning-light: #FFFBEB;
    --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;
    --white: #FFFFFF;
    --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-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px rgba(0,0,0,0.1), 0 10px 10px rgba(0,0,0,0.04);
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --transition: all 0.2s ease;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-hebrew: 'Heebo', 'Inter', sans-serif;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.5;
    min-height: 100vh;
}

body[data-lang="he"] {
    font-family: var(--font-hebrew);
}

.dir-rtl {
    direction: rtl;
    text-align: right;
}

.dir-ltr {
    direction: ltr;
    text-align: left;
}

/* Typography */
h1, h2, h3, h4 {
    color: var(--gray-900);
    font-weight: 600;
}

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

/* =============================================================================
   Top Navigation
   ============================================================================= */

.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 60px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    gap: 16px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
}

.nav-brand .fa-file-signature {
    font-size: 1.5rem;
}

.nav-back {
    color: var(--gray-600);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: var(--transition);
}

.nav-back:hover {
    background: var(--gray-100);
    color: var(--gray-800);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* =============================================================================
   Nav Tabs (in top bar)
   ============================================================================= */

.nav-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    justify-content: center;
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    background: transparent;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-500);
    transition: var(--transition);
    white-space: nowrap;
    position: relative;
}

.nav-tab:hover {
    color: var(--gray-700);
    background: var(--gray-50);
}

.nav-tab.active {
    color: var(--primary);
    background: var(--primary-light);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--primary);
    border-radius: 3px;
}

/* =============================================================================
   Buttons
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

.btn-outline {
    background: var(--white);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

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

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

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-500);
    font-size: 1rem;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

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

/* =============================================================================
   Main Container
   ============================================================================= */

.main-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* =============================================================================
   Tab Content & Toolbar
   ============================================================================= */

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tab-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 12px;
}

.view-toggle {
    display: flex;
    gap: 2px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 2px;
}

.view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--gray-400);
    transition: var(--transition);
    font-size: 0.875rem;
}

.view-btn:hover {
    color: var(--gray-600);
    background: var(--gray-50);
}

.view-btn.active {
    color: var(--primary);
    background: var(--primary-light);
}

.sort-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sort-select {
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--gray-700);
    background: var(--white);
    cursor: pointer;
}

/* =============================================================================
   Documents Grid
   ============================================================================= */

.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.doc-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: var(--transition);
    position: relative;
}

.doc-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--gray-300);
}

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

.doc-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.doc-card-icon.draft {
    background: var(--gray-100);
    color: var(--gray-500);
}

.doc-card-icon.active {
    background: var(--primary-light);
    color: var(--primary);
}

.doc-card-icon.signed {
    background: var(--success-light);
    color: var(--success);
}

.doc-card-menu {
    position: relative;
}

.doc-card-menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    color: var(--gray-400);
    border-radius: var(--radius);
    transition: var(--transition);
}

.doc-card-menu-btn:hover {
    background: var(--gray-100);
    color: var(--gray-600);
}

.doc-card-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    z-index: 50;
    display: none;
    overflow: hidden;
}

.dir-rtl .doc-card-dropdown {
    right: auto;
    left: 0;
}

.doc-card-dropdown.show {
    display: block;
}

.doc-card-dropdown button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--gray-700);
    transition: var(--transition);
    text-align: inherit;
}

.doc-card-dropdown button:hover {
    background: var(--gray-50);
}

.doc-card-dropdown button.danger {
    color: var(--danger);
}

.doc-card-dropdown button.danger:hover {
    background: var(--danger-light);
}

.doc-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 4px;
    word-break: break-word;
}

.doc-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-bottom: 12px;
}

.doc-card-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.doc-card-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-draft {
    background: var(--gray-100);
    color: var(--gray-600);
}

.status-active {
    background: var(--primary-light);
    color: var(--primary);
}

.status-signed {
    background: var(--success-light);
    color: var(--success);
}

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

/* =============================================================================
   Empty State
   ============================================================================= */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.empty-state i {
    font-size: 3rem;
    color: var(--gray-300);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--gray-600);
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--gray-400);
    margin-bottom: 20px;
}

/* =============================================================================
   Modals
   ============================================================================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--white);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 520px;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.2s ease;
}

.modal-sm {
    max-width: 440px;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-header h2 {
    font-size: 1.1rem;
}

.modal-body {
    padding: 24px;
}

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

/* =============================================================================
   Upload Zone
   ============================================================================= */

.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    transition: var(--transition);
    cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-icon {
    font-size: 2.5rem;
    color: var(--gray-300);
    margin-bottom: 16px;
}

.upload-zone:hover .upload-icon,
.upload-zone.dragover .upload-icon {
    color: var(--primary);
}

.upload-text {
    font-size: 0.95rem;
    color: var(--gray-600);
    margin-bottom: 16px;
}

.upload-hint {
    font-size: 0.8rem;
    color: var(--gray-400);
    margin-top: 12px;
}

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

.progress-bar {
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 12px;
}

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

.progress-text {
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* =============================================================================
   Share Link
   ============================================================================= */

.share-link-box {
    display: flex;
    gap: 8px;
}

.share-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--gray-700);
    background: var(--gray-50);
}

.share-copied {
    color: var(--success);
    font-size: 0.875rem;
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* =============================================================================
   Toast Notifications
   ============================================================================= */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dir-rtl .toast-container {
    right: auto;
    left: 24px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: var(--gray-800);
    color: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    animation: toastIn 0.3s ease;
    min-width: 260px;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
   List View
   ============================================================================= */

.documents-list {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.list-header {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.list-header .list-col {
    cursor: pointer;
}

.list-header .list-col:hover {
    color: var(--primary);
}

.list-header .list-col i {
    font-size: 0.65rem;
    margin-left: 4px;
    opacity: 0.5;
}

.dir-rtl .list-header .list-col i {
    margin-left: 0;
    margin-right: 4px;
}

.list-row {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.875rem;
    transition: var(--transition);
}

.list-row:last-child {
    border-bottom: none;
}

.list-row:hover {
    background: var(--gray-50);
}

.list-col {
    display: flex;
    align-items: center;
    gap: 8px;
}

.list-col-name {
    flex: 2;
    min-width: 0;
}

.list-col-name span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-col-pages,
.list-col-fields {
    flex: 0.5;
    justify-content: center;
}

.list-col-date {
    flex: 1.2;
    font-size: 0.8rem;
    color: var(--gray-500);
}

.list-col-status {
    flex: 0.8;
}

.list-col-ip {
    flex: 0.8;
    font-size: 0.8rem;
    color: var(--gray-500);
}

.list-col-actions {
    flex: 1.5;
    justify-content: flex-end;
    gap: 4px;
}

.dir-rtl .list-col-actions {
    justify-content: flex-start;
}

.list-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.list-icon.draft { color: var(--gray-400); }
.list-icon.active { color: var(--primary); }
.list-icon.signed { color: var(--success); }

.btn-outline-danger {
    color: var(--danger) !important;
    border-color: var(--danger) !important;
}

.btn-outline-danger:hover {
    background: var(--danger-light) !important;
}

/* =============================================================================
   Settings
   ============================================================================= */

.settings-container {
    max-width: 640px;
    margin: 0 auto;
}

.settings-heading {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 20px;
}

.settings-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 0;
    overflow: hidden;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    gap: 24px;
}

.settings-item-info {
    flex: 1;
}

.settings-item-info h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 4px;
}

.settings-item-info p {
    font-size: 0.8rem;
    color: var(--gray-500);
    line-height: 1.4;
}

.settings-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 0 24px;
}

.settings-select {
    padding: 8px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--gray-700);
    background: var(--white);
    cursor: pointer;
    min-width: 140px;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 30px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--gray-300);
    border-radius: 30px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    left: 3px;
    bottom: 3px;
    background: var(--white);
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.dir-rtl .toggle-slider::before {
    left: auto;
    right: 3px;
}

.dir-rtl .toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(-22px);
}

/* =============================================================================
   Loading Spinner
   ============================================================================= */

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.loading-spinner i {
    font-size: 2rem;
    margin-bottom: 12px;
}

/* =============================================================================
   Responsive
   ============================================================================= */

@media (max-width: 768px) {
    .top-nav {
        padding: 0 12px;
        gap: 8px;
    }

    .main-container {
        padding: 16px;
    }

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

    .btn span {
        display: none;
    }

    .btn i {
        margin: 0;
    }

    .nav-tabs {
        gap: 2px;
    }

    .nav-tab span {
        display: none;
    }

    .nav-tab {
        padding: 8px 12px;
    }

    /* List view: stack on mobile */
    .list-header {
        display: none;
    }

    .list-row {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px 16px;
    }

    .list-col-name {
        flex: 1 1 100%;
    }

    .list-col-pages,
    .list-col-fields {
        flex: 0 0 auto;
    }

    .list-col-date {
        flex: 1 1 100%;
    }

    .list-col-status {
        flex: 0 0 auto;
    }

    .list-col-actions {
        flex: 1 1 100%;
        justify-content: flex-start;
    }

    .settings-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .modal {
        margin: 10px;
        max-width: 100%;
    }
}
