/* WebApp - Juhi veebiliidese stiilid */

/* CSS Variables */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --white: #ffffff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --border-radius: 8px;
    --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);

    --header-height: 56px;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-100);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--header-height) + var(--safe-area-top));
    padding-top: var(--safe-area-top);
    background: var(--primary);
    color: var(--white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 8px;
    padding-right: 16px;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header.hidden {
    display: none;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
}

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

.user-name {
    font-size: 14px;
    opacity: 0.9;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

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

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

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

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

.btn-icon {
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(0, 0, 0, 0.1);
}

.btn-block {
    width: 100%;
}

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

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: var(--white);
    z-index: 200;
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
    padding-top: var(--safe-area-top);
}

.side-menu.open {
    transform: translateX(280px);
}

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

.menu-header h2 {
    font-size: 20px;
    color: var(--primary);
}

.menu-list {
    list-style: none;
    padding: 8px 0;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    color: var(--gray-700);
    text-decoration: none;
    transition: background 0.2s;
}

.menu-item:hover, .menu-item.active {
    background: var(--gray-100);
    color: var(--primary);
}

.menu-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 8px 16px;
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.menu-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Main content */
.main {
    padding-top: calc(var(--header-height) + var(--safe-area-top));
    padding-bottom: calc(20px + var(--safe-area-bottom));
    min-height: 100vh;
}

/* View container */
.view {
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
}

.view-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--gray-800);
}

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

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

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
}

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

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

.form-label.required::after {
    content: ' *';
    color: var(--danger);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius);
    background: var(--white);
    transition: border-color 0.2s, box-shadow 0.2s;
}

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

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

.form-hint {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 4px;
}

.form-error {
    font-size: 12px;
    color: var(--danger);
    margin-top: 4px;
}

/* Login view */
.login-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--white);
    border-radius: 16px;
    padding: 32px 24px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo h1 {
    font-size: 28px;
    color: var(--primary);
}

.login-logo p {
    color: var(--gray-500);
    font-size: 14px;
}

.pin-input {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 24px;
}

.pin-digit {
    width: 48px;
    height: 56px;
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    border: 2px solid var(--gray-300);
    border-radius: var(--border-radius);
    transition: border-color 0.2s;
}

.pin-digit:focus {
    outline: none;
    border-color: var(--primary);
}

/* Worksheet list */
.worksheet-list {
    list-style: none;
}

.worksheet-item {
    display: block;
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
}

.worksheet-item:active {
    transform: scale(0.98);
}

.worksheet-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.worksheet-number {
    font-weight: 600;
    color: var(--primary);
}

.worksheet-status {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 500;
}

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

.status-signed {
    background: #dcfce7;
    color: #166534;
}

.status-locked {
    background: #fef3c7;
    color: #92400e;
}

.status-cancelled {
    background: #fee2e2;
    color: #991b1b;
}

.worksheet-item-body {
    font-size: 14px;
    color: var(--gray-600);
}

.worksheet-client {
    font-weight: 500;
    color: var(--gray-800);
}

.worksheet-date {
    color: var(--gray-500);
}

/* FAB (Floating Action Button) */
.fab {
    position: fixed;
    bottom: calc(20px + var(--safe-area-bottom));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--white);
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
    z-index: 50;
}

.fab:hover {
    transform: scale(1.05);
    background: var(--primary-dark);
}

.fab:active {
    transform: scale(0.95);
}

/* GPS indicator */
.gps-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-radius: var(--border-radius);
    font-size: 14px;
}

.gps-status.success {
    background: #dcfce7;
    color: #166534;
}

.gps-status.error {
    background: #fee2e2;
    color: #991b1b;
}

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

/* Image upload */
.image-upload-area {
    border: 2px dashed var(--gray-300);
    border-radius: var(--border-radius);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.image-upload-area:hover {
    border-color: var(--primary);
    background: var(--gray-50);
}

.image-preview-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.image-preview {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--border-radius);
    overflow: hidden;
}

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--danger);
    color: var(--white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

/* Signature pad */
.signature-container {
    border: 2px solid var(--gray-300);
    border-radius: var(--border-radius);
    background: var(--white);
    position: relative;
}

.signature-pad {
    width: 100%;
    height: 200px;
    touch-action: none;
}

.signature-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* Items table */
.items-table {
    width: 100%;
    border-collapse: collapse;
}

.items-table th,
.items-table td {
    padding: 12px 8px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}

.items-table th {
    font-weight: 500;
    color: var(--gray-600);
    font-size: 12px;
    text-transform: uppercase;
}

.items-table .quantity {
    text-align: right;
}

.add-item-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.add-item-row .form-select {
    flex: 2;
}

.add-item-row .form-input {
    flex: 1;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    bottom: calc(80px + var(--safe-area-bottom));
    left: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--gray-800);
    color: var(--white);
    padding: 14px 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    pointer-events: auto;
}

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

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

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

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--white);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-overlay.visible .modal {
    transform: scale(1);
}

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

.modal-title {
    font-size: 18px;
    font-weight: 600;
}

.modal-body {
    padding: 16px;
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-500);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

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

/* Utility classes */
.hidden {
    display: none !important;
}

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

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

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

/* Responsive */
@media (min-width: 768px) {
    .login-card {
        padding: 40px 32px;
    }

    .view {
        padding: 24px;
    }
}
