/*
 * Lohnario – Custom Application Styles
 * Supplement to Tailwind CSS (loaded via CDN).
 * Dark mode is handled via the `dark` class on <html>.
 */

/* ─── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
    --color-bg:          #0f172a; /* slate-900  */
    --color-surface:     #1e293b; /* slate-800  */
    --color-border:      #334155; /* slate-700  */
    --color-text:        #e2e8f0; /* slate-200  */
    --color-muted:       #94a3b8; /* slate-400  */
    --color-accent:      #22c55e; /* green-500  */
    --color-accent-dark: #16a34a; /* green-600  */
    --color-danger:      #ef4444; /* red-500    */

    /* Safe-area insets for notched phones */
    --sab: env(safe-area-inset-bottom, 0px);
    --sat: env(safe-area-inset-top,    0px);
    --sal: env(safe-area-inset-left,   0px);
    --sar: env(safe-area-inset-right,  0px);
}

/* ─── Base Resets ────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    /* Prevent layout shift caused by scrollbar appearing/disappearing */
    overflow-y: scroll;
    /* Improve text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent tap highlight on mobile */
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--color-bg);
    color: var(--color-text);
    /* Reserve space for iOS bottom bar */
    padding-bottom: var(--sab);
}

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #334155; /* slate-700 */
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #475569; /* slate-600 */
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

/* ─── Focus Styles ───────────────────────────────────────────────────────── */
:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}
:focus:not(:focus-visible) {
    outline: none;
}

/* ─── Leaflet Map ────────────────────────────────────────────────────────── */
.leaflet-container {
    background: #1e293b !important;
    font-family: inherit;
}

/* Leaflet popup dark theme */
.leaflet-popup-content-wrapper {
    background: #1e293b;
    color: #e2e8f0;
    border: 1px solid #334155;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.leaflet-popup-tip {
    background: #1e293b;
}
.leaflet-popup-content {
    font-size: 0.875rem;
    margin: 12px 16px;
}
.leaflet-popup-close-button {
    color: #94a3b8 !important;
}

/* Leaflet zoom control */
.leaflet-control-zoom a {
    background: #1e293b !important;
    color: #e2e8f0 !important;
    border-color: #334155 !important;
}
.leaflet-control-zoom a:hover {
    background: #334155 !important;
}

/* Leaflet attribution */
.leaflet-control-attribution {
    background: rgba(15,23,42,.75) !important;
    color: #64748b !important;
    font-size: 10px !important;
    border-radius: 4px 0 0 0;
}
.leaflet-control-attribution a {
    color: #94a3b8 !important;
}

/* Map container defaults */
.map-container {
    width: 100%;
    height: 320px;
    border-radius: 0.75rem;
    overflow: hidden;
    position: relative;
    z-index: 0;
}

.map-container-tall {
    height: 420px;
}

/* Ensure map tiles are not blurry */
.leaflet-tile {
    filter: brightness(0.85) saturate(0.9);
}

/* Drawing toolbar */
.map-toolbar {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.map-toolbar button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 8px;
    color: #e2e8f0;
    cursor: pointer;
    transition: background 0.15s;
}
.map-toolbar button:hover {
    background: #334155;
}
.map-toolbar button.active {
    background: #166534;
    border-color: #22c55e;
    color: #4ade80;
}

/* ─── Signature Canvas ───────────────────────────────────────────────────── */
.signature-canvas-wrap {
    position: relative;
    background: #ffffff;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 2px solid #475569;
    touch-action: none;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
}

.signature-canvas-wrap canvas {
    display: block;
    width: 100%;
    cursor: crosshair;
    touch-action: none;
}

/* Fullscreen signature overlay – prevent iOS scroll/bounce behind it */
#sig-fullscreen {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
}
#sig-fullscreen canvas {
    touch-action: none;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
}

.signature-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    color: #94a3b8;
    font-size: 0.875rem;
    user-select: none;
}

/* Signature line */
.signature-line {
    position: absolute;
    bottom: 24px;
    left: 20px;
    right: 20px;
    height: 1px;
    background: #cbd5e1;
}

/* ─── Timer Display ──────────────────────────────────────────────────────── */
.timer-display {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
    font-feature-settings: "tnum";
}

.timer-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    animation: timer-pulse 1.2s ease-in-out infinite;
}

@keyframes timer-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.4; transform: scale(0.75); }
}

/* ─── GPS Indicator ──────────────────────────────────────────────────────── */
.gps-active-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #3b82f6;
    animation: gps-blink 2s ease-in-out infinite;
}

@keyframes gps-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.3; }
}

/* ─── Mobile Navigation ──────────────────────────────────────────────────── */
.mobile-nav {
    padding-bottom: var(--sab);
}

/* Touch targets: minimum 44×44px per Apple HIG */
.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ─── Form Elements ──────────────────────────────────────────────────────── */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="search"],
select,
textarea {
    /* Prevent iOS zoom-on-focus (font-size must be >= 16px) */
    font-size: 1rem;
}

/* Custom select arrow */
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 2.5rem;
}

/* File input */
input[type="file"] {
    cursor: pointer;
}

/* Range input */
input[type="range"] {
    accent-color: var(--color-accent);
}

/* ─── Status Badges ──────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.badge-open       { background: rgba(251,191,36,.1); color: #fbbf24; }
.badge-in-progress{ background: rgba(59,130,246,.1);  color: #60a5fa; }
.badge-done       { background: rgba(34,197,94,.1);   color: #4ade80; }
.badge-cancelled  { background: rgba(148,163,184,.1); color: #94a3b8; }
.badge-active     { background: rgba(34,197,94,.1);   color: #4ade80; }
.badge-inactive   { background: rgba(239,68,68,.1);   color: #f87171; }

/* ─── Card Hover Effects ─────────────────────────────────────────────────── */
.card-link {
    transition: border-color 0.15s, transform 0.15s;
}
.card-link:hover {
    border-color: rgba(34,197,94,.4);
    transform: translateY(-1px);
}
.card-link:active {
    transform: translateY(0);
}

/* ─── Loading Skeleton ───────────────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #1e293b 25%, #263248 50%, #1e293b 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 6px;
}

@keyframes skeleton-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── Photo Grid ─────────────────────────────────────────────────────────── */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}
.photo-grid-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: #1e293b;
    border: 1px solid #334155;
    cursor: pointer;
}
.photo-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}
.photo-grid-item:hover img {
    transform: scale(1.05);
}

/* ─── 2FA Input Boxes ────────────────────────────────────────────────────── */
.totp-input {
    width: 48px;
    height: 60px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0;
    font-variant-numeric: tabular-nums;
    caret-color: transparent;
    border: 2px solid #334155;
    border-radius: 12px;
    background: #1e293b;
    color: #f1f5f9;
    transition: border-color 0.15s, background 0.15s;
    outline: none;
}
.totp-input:focus {
    border-color: #22c55e;
    background: #0f2a1a;
}
.totp-input.filled {
    border-color: #4ade80;
}

/* ─── Offline Banner ─────────────────────────────────────────────────────── */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: #78350f;
    color: #fde68a;
    text-align: center;
    font-size: 0.8125rem;
    font-weight: 500;
    padding: calc(var(--sat) + 6px) 16px 6px;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}
.offline-banner.visible {
    transform: translateY(0);
}

/* ─── PWA Install Button ─────────────────────────────────────────────────── */
#pwa-install-btn {
    display: none;
}
#pwa-install-btn.visible {
    display: flex;
}

/* ─── Print Styles ───────────────────────────────────────────────────────── */
@media print {
    body {
        background: white;
        color: black;
    }
    .no-print,
    nav,
    aside,
    .mobile-nav {
        display: none !important;
    }
}

/* ─── Reduced Motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ─── Utility Overrides ──────────────────────────────────────────────────── */

/* Prevent content from going under iOS home indicator */
.pb-safe {
    padding-bottom: var(--sab);
}

/* Full-height layout helper */
.h-screen-safe {
    height: calc(100vh - var(--sab) - var(--sat));
}

/* Mono font for IDs, slugs, tokens */
.font-mono-sm {
    font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Monaco, Consolas, monospace;
    font-size: 0.8125rem;
}

/* Truncate with tooltip support */
.truncate-tooltip {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: default;
}

/* Divider with text */
.divider-text {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #475569;
    font-size: 0.75rem;
}
.divider-text::before,
.divider-text::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #334155;
}

/* Table: sticky header */
.table-sticky thead th {
    position: sticky;
    top: 0;
    background: #1e293b;
    z-index: 10;
}

/* Highlight on row select */
tr.selected {
    background: rgba(34,197,94,.08) !important;
}

/* Success flash */
@keyframes flash-success {
    0%   { opacity: 0; transform: translateY(-8px); }
    15%  { opacity: 1; transform: translateY(0); }
    85%  { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-8px); }
}
.flash-animate {
    animation: flash-success 5s ease forwards;
}
