/* ============================================================
   LAPIN QUALITY - Mobile-first stylesheet
   ============================================================ */

:root {
    --primary:        #E76F51;
    --primary-dark:   #C25538;
    --primary-light:  #FCE9E2;
    --secondary:      #264653;
    --accent:         #F4A261;
    --success:        #2A9D8F;
    --warning:        #F4A261;
    --danger:         #E63946;
    --info:           #3B82F6;

    --bg:             #FAF7F4;
    --bg-soft:        #F4EFE9;
    --card:           #FFFFFF;
    --border:         #EFE5DA;
    --border-strong:  #DDD0C0;

    --text:           #1F2937;
    --text-soft:      #4B5563;
    --text-muted:     #9CA3AF;

    --shadow-sm:      0 1px 2px rgba(38, 70, 83, 0.05);
    --shadow:         0 2px 8px rgba(38, 70, 83, 0.08);
    --shadow-lg:      0 8px 24px rgba(38, 70, 83, 0.12);

    --radius-sm:      8px;
    --radius:         12px;
    --radius-lg:      16px;
    --radius-xl:      24px;

    --space-1:        4px;
    --space-2:        8px;
    --space-3:        12px;
    --space-4:        16px;
    --space-5:        20px;
    --space-6:        24px;
    --space-8:        32px;

    --header-h:       56px;
    --bottom-nav-h:   64px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Inter', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

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

img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; cursor: pointer; }

input, textarea, select { font-family: inherit; font-size: 16px; /* prevent iOS zoom */ }

/* ====== TOP HEADER ====== */
.top-header {
    position: sticky; top: 0; z-index: 100;
    height: var(--header-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 var(--space-4);
    gap: var(--space-3);
}
.brand {
    display: flex; align-items: center; gap: 8px;
    font-weight: 800; font-size: 16px; color: var(--primary);
    text-decoration: none;
    letter-spacing: -0.5px;
}
.brand-mark {
    width: 30px; height: 30px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 800; font-size: 14px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small {
    font-size: 9px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1px;
}
.top-spacer { flex: 1; }

.icon-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-soft);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px;
    transition: background 0.15s;
    text-decoration: none;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--primary); }

.user-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-weight: 700; font-size: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

/* ====== LAYOUT ====== */
.app-layout {
    display: flex;
    min-height: calc(100vh - var(--header-h));
}
.sidebar {
    width: 240px;
    background: var(--card);
    border-right: 1px solid var(--border);
    padding: var(--space-4);
    flex-shrink: 0;
    display: none; /* hidden on mobile */
}
.main-content {
    flex: 1;
    min-width: 0;
    padding: var(--space-4);
    padding-bottom: calc(var(--bottom-nav-h) + var(--space-4));
}

@media (min-width: 900px) {
    .sidebar { display: block; }
    .main-content { padding: var(--space-6); padding-bottom: var(--space-8); }
}

.sidebar-section {
    margin-bottom: var(--space-5);
}
.sidebar-title {
    font-size: 10px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1.5px;
    margin-bottom: var(--space-2);
    padding: 0 var(--space-2);
}
.sidebar a {
    display: flex; align-items: center; gap: var(--space-3);
    padding: 10px var(--space-3);
    color: var(--text-soft);
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500;
    transition: background 0.15s, color 0.15s;
    margin-bottom: 2px;
}
.sidebar a:hover { background: var(--bg-soft); color: var(--text); }
.sidebar a.active {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
}
.sidebar a i { font-size: 16px; flex-shrink: 0; }

/* ====== BOTTOM NAV (mobile) ====== */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 90;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.04);
}
.bottom-nav a {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-muted);
    font-size: 10px; font-weight: 600;
    gap: 2px;
    text-decoration: none;
    transition: color 0.15s;
}
.bottom-nav a i { font-size: 22px; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav .nav-fab {
    flex: 0 0 56px;
    margin-top: -22px;
}
.bottom-nav .nav-fab .fab-circle {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff !important;
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
    box-shadow: 0 4px 16px rgba(231, 111, 81, 0.5);
}
.bottom-nav .nav-fab span { color: var(--primary); margin-top: 2px; }

@media (min-width: 900px) {
    .bottom-nav { display: none; }
    .main-content { padding-bottom: var(--space-8); }
}

/* ====== PAGE TITLE ====== */
.page-head {
    margin-bottom: var(--space-5);
    display: flex; align-items: flex-end; justify-content: space-between;
    gap: var(--space-3); flex-wrap: wrap;
}
.page-head h1 {
    margin: 0; font-size: 22px; font-weight: 800;
    color: var(--text); letter-spacing: -0.5px;
}
.page-head .subtitle {
    color: var(--text-muted); font-size: 13px; margin-top: 2px;
}

/* ====== CARDS ====== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    box-shadow: var(--shadow-sm);
}
.card.tight { padding: var(--space-3); }
.card.flat  { box-shadow: none; }

/* ====== FEED / WALL ====== */
.feed-filters {
    display: flex; gap: var(--space-2);
    overflow-x: auto;
    margin-bottom: var(--space-4);
    padding-bottom: 4px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}
.feed-filters::-webkit-scrollbar { height: 4px; }
.feed-filters::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    border-radius: 999px;
    background: var(--card);
    border: 1px solid var(--border-strong);
    color: var(--text-soft);
    font-size: 13px; font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    flex-shrink: 0;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.chip i { font-size: 12px; }
.chip-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 18px;
    padding: 0 6px;
    background: rgba(0, 0, 0, 0.07);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-soft);
    margin-left: 4px;
    line-height: 1;
}
.chip.active .chip-count {
    background: rgba(255, 255, 255, 0.28);
    color: #fff;
}

.feed-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
}
@media (min-width: 600px) {
    .feed-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1100px) {
    .feed-grid { grid-template-columns: repeat(3, 1fr); }
}

.defect-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
    display: flex; flex-direction: column;
}
.defect-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}
.defect-card-link { color: inherit; display: block; }

.defect-img {
    width: 100%; aspect-ratio: 1/1;
    background: var(--bg-soft);
    object-fit: contain;
    display: block;
    padding: 8px;
}
.defect-img-placeholder {
    width: 100%; aspect-ratio: 1/1;
    background: linear-gradient(135deg, var(--bg-soft), var(--border));
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 32px;
}

.defect-body { padding: var(--space-4); }

.defect-meta {
    display: flex; align-items: center; gap: var(--space-2);
    font-size: 11px; color: var(--text-muted);
    margin-bottom: var(--space-2);
    flex-wrap: wrap;
}
.defect-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-muted); }

.defect-title {
    font-size: 15px; font-weight: 700; color: var(--text);
    margin: 0 0 var(--space-1);
    line-height: 1.3;
    /* clamp 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.defect-desc {
    font-size: 13px; color: var(--text-soft);
    margin: 0 0 var(--space-3);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tag-row {
    display: flex; flex-wrap: wrap; gap: 6px;
    margin-bottom: var(--space-3);
}
.tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--bg-soft);
    color: var(--text-soft);
    font-size: 11px; font-weight: 600;
}
.tag.tag-cat { color: #fff; }
.tag.tag-code { font-family: 'SF Mono', Menlo, monospace; background: #FEF3E2; color: #C25538; }

.defect-foot {
    display: flex; align-items: center; justify-content: space-between;
    padding-top: var(--space-3);
    border-top: 1px solid var(--border);
    font-size: 12px; color: var(--text-muted);
}
.defect-foot .actions {
    display: flex; align-items: center; gap: var(--space-3);
}
.defect-foot .actions span {
    display: inline-flex; align-items: center; gap: 4px;
}

/* ====== STATUS BADGES ====== */
.badge-status {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-status.st-open     { background: #FEE2E2; color: #B91C1C; }
.badge-status.st-review   { background: #FEF3C7; color: #B45309; }
.badge-status.st-resolved { background: #D1FAE5; color: #047857; }

/* ====== BUTTONS ====== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 14px; font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary {
    background: var(--card);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost {
    background: transparent; color: var(--text-soft); border: none;
}
.btn-ghost:hover { background: var(--bg-soft); }
.btn-danger {
    background: var(--danger); color: #fff;
}
.btn-success {
    background: var(--success); color: #fff;
}
.btn-block { width: 100%; }
.btn-lg { padding: 14px 22px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ====== FAB ====== */
.fab {
    position: fixed;
    right: 20px;
    bottom: calc(var(--bottom-nav-h) + 16px);
    width: 56px; height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    border: none;
    box-shadow: 0 6px 20px rgba(231, 111, 81, 0.5);
    z-index: 95;
    text-decoration: none;
    transition: transform 0.15s;
}
.fab:hover { transform: scale(1.05); color: #fff; }
@media (min-width: 900px) {
    .fab { bottom: 28px; right: 28px; }
}

/* ====== FORMS ====== */
.field { margin-bottom: var(--space-4); }
.field label {
    display: block;
    font-size: 12px; font-weight: 700; color: var(--text-soft);
    margin-bottom: 6px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.field label .req { color: var(--danger); }
.field .hint {
    margin-top: 4px; font-size: 11px; color: var(--text-muted);
}

.input, .select, .textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--text);
    font-size: 15px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.textarea { min-height: 100px; resize: vertical; }

.field-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
}
@media (min-width: 600px) {
    .field-row.cols-2 { grid-template-columns: 1fr 1fr; }
    .field-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
}

/* Photo picker (camera) */
.photo-picker {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: var(--space-5);
    text-align: center;
    background: var(--bg-soft);
    transition: all 0.15s;
    cursor: pointer;
    color: var(--text-soft);
}
.photo-picker:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary-dark);
}
.photo-picker i { font-size: 32px; display: block; margin-bottom: 8px; }
.photo-picker input[type=file] { display: none; }
.photo-picker .pp-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.photo-picker .pp-hint  { font-size: 11px; color: var(--text-muted); }

.photo-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    margin-top: 12px;
}
.photo-preview {
    position: relative;
    aspect-ratio: 1/1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-soft);
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview .rm {
    position: absolute; top: 4px; right: 4px;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    color: #fff;
    border: none;
    font-size: 12px;
    display: flex; align-items: center; justify-content: center;
}

/* ====== FLASH ====== */
.flash-msg {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-4);
    font-size: 14px; font-weight: 500;
    border-left: 4px solid;
}
.flash-success { background: #D1FAE5; color: #065F46; border-color: #10B981; }
.flash-danger  { background: #FEE2E2; color: #991B1B; border-color: #EF4444; }
.flash-warning { background: #FEF3C7; color: #92400E; border-color: #F59E0B; }
.flash-info    { background: #DBEAFE; color: #1E40AF; border-color: #3B82F6; }

/* ====== LOGIN ====== */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: var(--space-4);
    background: linear-gradient(135deg, #F4EFE9, #FCE9E2);
}
.login-card {
    width: 100%; max-width: 400px;
    background: var(--card);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    box-shadow: var(--shadow-lg);
}
.login-logo {
    text-align: center;
    margin-bottom: var(--space-6);
}
.login-logo .brand-mark {
    width: 64px; height: 64px;
    font-size: 28px;
    margin: 0 auto var(--space-3);
}
.login-logo h1 {
    margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.5px;
}
.login-logo p {
    margin: 4px 0 0; font-size: 13px; color: var(--text-muted);
}

/* ====== TABLES ====== */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.table th {
    text-align: left;
    padding: 12px var(--space-4);
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    color: var(--text-muted); letter-spacing: 0.5px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td {
    padding: 12px var(--space-4);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-soft); }

/* ====== STATS GRID ====== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}
@media (min-width: 700px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }

.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    position: relative; overflow: hidden;
}
.stat .label {
    font-size: 11px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.stat .value {
    font-size: 26px; font-weight: 800; color: var(--text);
    line-height: 1;
}
.stat .ico {
    position: absolute; top: 12px; right: 12px;
    width: 36px; height: 36px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.stat.ok    .ico { background: #D1FAE5; color: #047857; }
.stat.warn  .ico { background: #FEF3C7; color: #B45309; }
.stat.danger .ico { background: #FEE2E2; color: #B91C1C; }
.stat.info  .ico { background: var(--primary-light); color: var(--primary-dark); }

/* ====== DETAIL VIEW ====== */
.detail-hero {
    background: var(--card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: var(--space-5);
    max-width: 720px;
}
.detail-gallery {
    display: grid;
    gap: 4px;
    grid-template-columns: 1fr;
    background: var(--bg-soft);
}
.detail-gallery.has-2 { grid-template-columns: 1fr 1fr; }
.detail-gallery.has-3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.detail-gallery.has-3 > :first-child { grid-row: span 2; }
.detail-gallery.has-many { grid-template-columns: 2fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.detail-gallery.has-many > :first-child { grid-row: span 2; }
.detail-gallery img {
    width: 100%; height: 100%; min-height: 220px; max-height: 480px;
    object-fit: cover; cursor: pointer;
}
/* When there's a single image, contain it so nothing gets cut off */
.detail-gallery:not(.has-2):not(.has-3):not(.has-many) img {
    object-fit: contain;
    background: var(--bg-soft);
    max-height: 560px;
    min-height: 320px;
}
.detail-body { padding: var(--space-5); }

.comment {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
}
.comment-head {
    display: flex; align-items: center; gap: var(--space-2);
    margin-bottom: var(--space-2);
    font-size: 13px;
}
.comment-head .who { font-weight: 700; }
.comment-head .when { color: var(--text-muted); font-size: 12px; }
.comment-body { font-size: 14px; color: var(--text-soft); white-space: pre-wrap; }

/* ====== EMPTY STATE ====== */
.empty {
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--text-muted);
}
.empty i { font-size: 48px; opacity: 0.5; display: block; margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--text-soft); font-weight: 700; font-size: 16px; }
.empty p { margin: 0; font-size: 13px; }

/* ====== UTILITIES ====== */
.text-muted { color: var(--text-muted); }
.text-soft  { color: var(--text-soft); }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-bold { font-weight: 700; }
.fw-semi { font-weight: 600; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--space-1) !important; }
.mb-2 { margin-bottom: var(--space-2) !important; }
.mb-3 { margin-bottom: var(--space-3) !important; }
.mb-4 { margin-bottom: var(--space-4) !important; }
.mb-5 { margin-bottom: var(--space-5) !important; }
.mt-3 { margin-top: var(--space-3) !important; }
.mt-4 { margin-top: var(--space-4) !important; }
.mt-5 { margin-top: var(--space-5) !important; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.d-flex { display: flex; }
.flex-1 { flex: 1; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.full-w { width: 100%; }

/* Hide elements responsively */
.show-mobile { display: block; }
.show-desktop { display: none; }
@media (min-width: 900px) {
    .show-mobile  { display: none !important; }
    .show-desktop { display: block; }
    .show-desktop-flex { display: flex; }
}