/* ===== CSS Variables ===== */
:root {
    --primary: #1a237e;
    --primary-light: #3949ab;
    --accent: #ff6f00;
    --accent-light: #ffa040;
    --accent-dark: #c43e00;

    --bg: #0f1419;
    --bg-card: #1a1f2e;
    --bg-card-hover: #242b3d;
    --bg-input: #252d40;

    --text: #ffffff;
    --text-secondary: #a0aec0;
    --text-muted: #718096;

    --border: #2d3748;
    --success: #48bb78;
    --danger: #fc8181;
    --warning: #f6ad55;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);

    --header-height: 56px;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

/* ===== Reset ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

input,
select,
textarea,
button {
    font-family: inherit;
    font-size: 16px;
    /* Prevents zoom on iOS */
}

a {
    color: inherit;
    text-decoration: none;
}

/* ===== App Container ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

/* ===== Header ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    padding-top: var(--safe-top);
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex;
    align-items: center;
    padding-left: 8px;
    padding-right: 8px;
    z-index: 100;
    box-shadow: var(--shadow);
}

.header-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.header-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

.header-btn svg {
    width: 24px;
    height: 24px;
}

.header-title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: white;
}

/* ===== Sidebar ===== */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 199;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg-card);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-top);
}

.sidebar.active {
    transform: translateX(0);
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo .logo-icon {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.sidebar-logo span {
    font-size: 16px;
    font-weight: 600;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
    margin-bottom: 4px;
}

.nav-link svg {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.nav-link.active {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
}

.nav-link:active {
    background: var(--bg-card-hover);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-top: calc(var(--header-height) + var(--safe-top));
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.page {
    display: none;
    padding: 20px 16px;
    padding-bottom: calc(20px + var(--safe-bottom));
    min-height: 100%;
}

.page.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Home Menu Grid ===== */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.menu-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 28px 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.menu-card:active {
    transform: scale(0.98);
    background: var(--bg-card-hover);
}

.menu-card.accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border-color: transparent;
}

.menu-card-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-card-icon svg {
    width: 32px;
    height: 32px;
}

.menu-card span {
    font-size: 14px;
    font-weight: 500;
}

.menu-card-full {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.menu-card-full svg {
    width: 24px;
    height: 24px;
}

.menu-card-full span {
    font-size: 15px;
    font-weight: 500;
}

/* ===== Form Elements ===== */
.form-container {
    max-width: 100%;
}

.form-section {
    margin-bottom: 24px;
}

.form-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

.form-row .form-group.small {
    flex: 0.5;
}

.form-row .form-group.flex-2 {
    flex: 2;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    transition: all 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 111, 0, 0.15);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23a0aec0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 40px;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

.form-divider {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 20px 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
}

.btn svg {
    width: 20px;
    height: 20px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-accent {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #38a169);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-add {
    width: 100%;
    background: transparent;
    color: var(--accent);
    border: 1px dashed var(--accent);
    padding: 14px;
}

.btn-block {
    width: 100%;
}

.action-buttons {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.action-buttons .btn {
    flex: 1;
}

/* ===== FAB (Floating Action Button) ===== */
.fab {
    position: fixed;
    right: 20px;
    bottom: calc(20px + var(--safe-bottom));
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border: none;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(255, 111, 0, 0.4);
    cursor: pointer;
    z-index: 50;
}

.fab svg {
    width: 24px;
    height: 24px;
}

.fab:active {
    transform: scale(0.95);
}

/* ===== Search Bar ===== */
.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-input);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

.search-bar svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-bar input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    padding: 0;
}

.search-bar input:focus {
    outline: none;
    box-shadow: none;
}

/* ===== List Container ===== */
.list-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.list-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.list-item:active {
    background: var(--bg-card-hover);
}

.list-avatar {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    margin-right: 14px;
    flex-shrink: 0;
}

.list-info {
    flex: 1;
    min-width: 0;
}

.list-title {
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-actions {
    display: flex;
    gap: 8px;
    margin-left: 8px;
}

.list-actions .btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.list-actions .btn-icon svg {
    width: 18px;
    height: 18px;
}

.list-actions .btn-icon.danger {
    color: var(--danger);
    border-color: var(--danger);
}

/* ===== Items List Edit (Services/Parts) ===== */
.items-list-edit {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.item-card {
    display: flex;
    align-items: center;
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-desc {
    font-size: 14px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-details {
    font-size: 12px;
    color: var(--text-muted);
}

.item-total {
    font-weight: 600;
    color: var(--accent);
    margin-left: 12px;
}

.item-remove {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--danger);
    cursor: pointer;
    margin-left: 8px;
    opacity: 0.7;
}

.item-remove svg {
    width: 18px;
    height: 18px;
}

/* ===== Totals Box ===== */
.totals-box {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin: 20px 0;
    border: 1px solid var(--border);
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 15px;
}

.total-row.total-final {
    border-top: 1px solid var(--border);
    margin-top: 8px;
    padding-top: 16px;
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

/* ===== OS Header ===== */
.os-header {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.os-numero {
    flex: 1;
}

.os-numero label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.os-numero span {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.os-data {
    flex: 1;
}

.os-data label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

/* ===== Filter Tabs ===== */
.filter-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.filter-tab {
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.filter-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ===== History Item ===== */
.history-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 8px;
}

.history-type {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 14px;
    flex-shrink: 0;
}

.history-type.orcamento {
    background: rgba(255, 111, 0, 0.15);
    color: var(--accent);
}

.history-type.os {
    background: rgba(72, 187, 120, 0.15);
    color: var(--success);
}

.history-type svg {
    width: 20px;
    height: 20px;
}

.history-info {
    flex: 1;
    min-width: 0;
}

.history-title {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 2px;
}

.history-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.history-value {
    text-align: right;
    margin-left: 12px;
}

.history-value-amount {
    font-weight: 600;
    color: var(--accent);
    font-size: 15px;
}

.history-value-date {
    font-size: 11px;
    color: var(--text-muted);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    background: var(--bg-card);
    border-radius: var(--radius) var(--radius) 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--safe-bottom);
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-small {
    max-width: 350px;
    margin: auto;
    border-radius: var(--radius);
    padding: 24px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 20px;
    border-top: 1px solid var(--border);
}

.modal-footer .btn {
    flex: 1;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: calc(80px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    padding: 14px 24px;
    border-radius: 50px;
    box-shadow: var(--shadow);
    opacity: 0;
    transition: all 0.3s;
    z-index: 400;
    border: 1px solid var(--border);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--success);
    border-color: var(--success);
}

.toast.error {
    background: var(--danger);
    border-color: var(--danger);
}

.toast-message {
    font-size: 14px;
    font-weight: 500;
}

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 15px;
}

/* ===== Utilities ===== */
.text-accent {
    color: var(--accent);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.text-muted {
    color: var(--text-muted);
}

.mt-16 {
    margin-top: 16px;
}

.mb-16 {
    margin-bottom: 16px;
}

/* ===== Login Screen ===== */
.login-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--bg) 0%, #1a1f2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 320px;
    text-align: center;
}

.login-logo {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
    box-shadow: 0 8px 32px rgba(26, 35, 126, 0.4);
}

.login-logo svg {
    width: 40px;
    height: 40px;
    color: var(--accent);
}

.login-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-form {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.login-form .form-group {
    margin-bottom: 20px;
    text-align: left;
}

.login-form input[type="password"] {
    font-size: 18px;
    text-align: center;
    letter-spacing: 4px;
}

.login-error {
    color: var(--danger);
    font-size: 14px;
    margin-bottom: 16px;
    padding: 10px;
    background: rgba(252, 129, 129, 0.1);
    border-radius: var(--radius-sm);
}

.login-screen.hidden {
    display: none;
}