:root {
    --primary: #0f3b70;
    --primary-dark: #092547;
    --primary-light: #1e5aa0;
    --accent: #0284c7;
    --accent-hover: #0369a1;
    --success: #059669;
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;
    --info-bg: #eff6ff;
    --info-border: #bfdbfe;
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #cbd5e1;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-card: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
}

body.dark-theme {
    --primary: #1e293b;
    --primary-dark: #0f172a;
    --primary-light: #334155;
    --accent: #38bdf8;
    --bg-page: #0b0f19;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --success-bg: #064e3b;
    --success-border: #047857;
    --info-bg: #1e3a8a;
    --info-border: #1d4ed8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #e2e8f0;
    color: var(--text-main);
    display: flex;
    justify-content: center;
    min-height: 100vh;
    overflow-x: hidden;
}

#app-container {
    width: 100%;
    max-width: 540px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-page);
    position: relative;
    padding-bottom: 90px;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.08);
}

/* App Header */
.app-header {
    background-color: var(--primary);
    color: #ffffff;
    padding: 12px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

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

.app-logo {
    font-size: 22px;
}

.app-title {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.app-subtitle {
    font-size: 11px;
    color: #93c5fd;
    font-weight: 500;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.badge {
    background-color: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
}

.clock {
    font-size: 11px;
    color: #cbd5e1;
    font-weight: 600;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 12px;
}

.page {
    display: none;
    flex-direction: column;
    gap: 10px;
}

.page.active {
    display: flex;
    animation: fadeIn 0.15s ease-out;
}

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

/* Unified Main Card */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px;
    box-shadow: var(--shadow-card);
}

.main-form-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.section-label {
    font-size: 12px;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-badge {
    background-color: #dbeafe;
    color: #1d4ed8;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
}

.divider {
    height: 1px;
    background-color: var(--border-color);
    opacity: 0.6;
    margin: 2px 0;
}

/* Input Fields */
.coord-field label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 4px;
}

input[type="text"], input[type="search"] {
    width: 100%;
    padding: 9px 12px;
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text-main);
    background-color: var(--bg-card);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus, input[type="search"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

.input-with-action {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background-color: #dbeafe;
    color: #1d4ed8;
    font-weight: 700;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius-sm);
    padding: 0 12px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}

.btn-icon:active {
    background-color: #bfdbfe;
}

/* Coordinates Grid */
.coords-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Results Grid */
.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 2px;
}

.result-box {
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}

.result-lat {
    background-color: var(--success-bg);
    border: 1.5px solid var(--success-border);
}

.result-long {
    background-color: var(--info-bg);
    border: 1.5px solid var(--info-border);
}

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

.result-label {
    font-size: 11px;
    font-weight: 800;
}

.result-lat .result-label { color: #065f46; }
.result-long .result-label { color: #1e40af; }

.result-formula {
    font-size: 9px;
    font-weight: 700;
    opacity: 0.7;
}

.result-value-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
}

.result-display {
    border: none !important;
    background: transparent !important;
    padding: 2px 0 !important;
    font-size: 16px !important;
    font-weight: 800 !important;
    width: 100% !important;
    box-shadow: none !important;
}

.result-lat .result-display { color: #047857; }
.result-long .result-display { color: #1d4ed8; }

.btn-copy-mini {
    background: transparent;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 2px;
    opacity: 0.8;
}

.btn-copy-mini:active {
    transform: scale(1.15);
}

/* Action Buttons Grid */
.actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 2px;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 12px;
    font-size: 13.5px;
    font-weight: 700;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:active {
    transform: scale(0.97);
}

.btn-save {
    background-color: var(--success);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
}

.btn-save-next {
    background-color: #0284c7;
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.25);
}

.btn-clear {
    background-color: #e2e8f0;
    color: #334155;
}

.btn-pdf {
    background-color: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.btn-primary-full {
    width: 100%;
    background-color: #0284c7;
    color: #ffffff;
    padding: 12px;
    margin-bottom: 8px;
}

.btn-outline-full {
    width: 100%;
    background-color: var(--bg-card);
    border: 1.5px solid var(--border-color);
    color: var(--text-main);
    padding: 12px;
    margin-bottom: 8px;
}

/* Records Ledger List */
.ledger-header-row {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
}

.search-bar {
    flex: 1;
}

.btn-danger-outline {
    background: transparent;
    border: 1.5px solid #fca5a5;
    color: #dc2626;
    font-weight: 700;
    font-size: 12px;
    border-radius: var(--radius-sm);
    padding: 0 12px;
    cursor: pointer;
}

.records-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    padding-bottom: 10px;
}

.record-item-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    box-shadow: var(--shadow-card);
}

.rec-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}

.rec-id {
    font-weight: 800;
    font-size: 13.5px;
    color: var(--primary-light);
}

.rec-time {
    font-size: 10.5px;
    color: var(--text-muted);
}

.rec-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    font-size: 11.5px;
    margin-bottom: 6px;
}

.rec-grid-item span:first-child {
    color: var(--text-muted);
    font-size: 10.5px;
    display: block;
}

.rec-res1 { color: #047857; font-weight: 700; }
.rec-res2 { color: #1d4ed8; font-weight: 700; }

.rec-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.btn-mini {
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 4px;
    border: none;
    cursor: pointer;
}

.btn-mini-pdf { background-color: #dbeafe; color: #1d4ed8; }
.btn-mini-del { background-color: #fee2e2; color: #dc2626; }

/* Settings */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-title {
    display: block;
    font-weight: 700;
    font-size: 13px;
}

.setting-desc {
    font-size: 11px;
    color: var(--text-muted);
}

.toggle-switch {
    width: 40px;
    height: 22px;
    accent-color: #0284c7;
    cursor: pointer;
}

/* Bottom Navigation Bar */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 540px;
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 100;
}

.nav-item {
    background: transparent;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 5px 0;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    transition: color 0.15s ease;
}

.nav-icon {
    font-size: 18px;
}

.nav-label {
    font-size: 10.5px;
    font-weight: 700;
}

.nav-item.active {
    color: #0284c7;
}

.nav-item.active .nav-icon {
    transform: scale(1.1);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 75px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: #0f172a;
    color: #ffffff;
    padding: 8px 18px;
    border-radius: 30px;
    font-size: 12.5px;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 200;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Header Phone Link Button */
.btn-header-link {
    background-color: #22c55e;
    color: #ffffff;
    font-weight: 800;
    font-size: 11.5px;
    border: none;
    border-radius: 20px;
    padding: 5px 12px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(34, 197, 94, 0.35);
    transition: transform 0.1s ease, background-color 0.15s ease;
}

.btn-header-link:hover {
    background-color: #16a34a;
}

.btn-header-link:active {
    transform: scale(0.95);
}

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

.header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

/* Modal Styling */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 500;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.15s ease-out;
}

.modal-content {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 20px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.modal-header h3 {
    font-size: 15px;
    font-weight: 800;
    color: var(--primary-light);
}

.btn-close {
    background: transparent;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.modal-desc {
    font-size: 12.5px;
    color: var(--text-muted);
    line-height: 1.4;
}

.qr-box {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 14px;
    width: 200px;
    height: 200px;
    margin: 0 auto;
}

.qr-box img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.phone-url-box {
    display: flex;
    gap: 6px;
}

.phone-url-box input {
    font-size: 12px !important;
    padding: 7px 10px !important;
    background-color: #f8fafc !important;
}

.modal-notes {
    font-size: 11.5px;
    color: var(--text-muted);
    background-color: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 6px;
    padding: 8px 10px;
    text-align: left;
}

