/* =========================================================
   Construction Task System - Single stylesheet
   Mobile-first, RTL-aware
   Modern rounded / "floating pill" SaaS look, sticky header
   ========================================================= */

:root {
    --color-primary: #4F46E5;
    --color-primary-dark: #4338CA;
    --color-primary-soft: #EEF0FF;
    --color-danger: #E11D48;
    --color-success: #16A34A;
    --color-bg: #F3F4FB;
    --color-card: #ffffff;
    --color-border: #E7E8F3;
    --color-text: #1E1B3A;
    --color-muted: #6B7280;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-pill: 999px;
    --shadow-card: 0 1px 2px rgba(30, 27, 58, 0.04), 0 8px 24px rgba(30, 27, 58, 0.05);
    --shadow-header: 0 2px 16px rgba(30, 27, 58, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px;
    width: 100%;
    flex: 1 0 auto;
}

/* On genuinely large screens, scale with the viewport (85%) instead of
   stopping at a fixed pixel value - mobile/tablet are unaffected since
   this only kicks in above 1024px. */
@media (min-width: 1024px) {
    .container { max-width: 85%; }
}

/* --- Topbar: sticky + soft blur --- */
.topbar {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-border);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-header);
    flex-shrink: 0;
}
.topbar-title { font-weight: 600; }
.topbar-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand {
    font-weight: 700;
    text-decoration: none;
    color: var(--color-text);
    font-size: 17px;
    letter-spacing: -0.2px;
}
.admin-nav { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Header dropdown (Reports) --- */
.dropdown { position: relative; }
.dropdown-menu {
    display: none;
    flex-direction: column;
    gap: 2px;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-card);
    min-width: 170px;
    z-index: 200;
    padding: 6px;
}
.dropdown-menu.open {
    display: flex;
}
.dropdown-menu a {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--color-text);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}
.dropdown-menu a:hover { background: var(--color-bg); }
.user-name { font-size: 14px; color: var(--color-muted); }
.topbar-user { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.back-link { color: var(--color-primary); text-decoration: none; font-weight: 600; }

/* --- Admin tables --- */
.table-scroll { overflow-x: auto; margin-top: 10px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; white-space: nowrap; }
.admin-table th, .admin-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
}
.admin-table th { color: var(--color-muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.3px; }

/* --- Modal overlay (used by Projects screen row -> edit popup) --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(30, 27, 58, 0.45);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: #fff;
    border-radius: var(--radius);
    padding: 20px;
    width: 100%;
    max-width: 640px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(30, 27, 58, 0.25);
}
.modal-box-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.modal-box-top h2 { margin: 0; font-size: 17px; }
.modal-close-btn {
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: var(--color-muted);
    padding: 4px 8px;
}
.modal-close-btn:hover { color: var(--color-text); }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--color-bg); }

/* --- Project cards (spacious layout, replaces the old cramped grid) --- */
.project-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 10px;
}
.project-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    background: #fff;
    box-shadow: var(--shadow-card);
}
.project-card-closed { opacity: 0.65; }
.project-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}
.project-card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.project-card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 6px;
}
@media (min-width: 640px) {
    .project-card-grid { grid-template-columns: repeat(3, 1fr); }
    .project-card-grid:has(.tag-select) { grid-template-columns: 1fr 1fr; }
}
.project-card .field { margin-bottom: 0; }
.project-card .tag-select { padding: 0 !important; }

/* --- Editable row list (Categories, Projects, Sub-projects) --- */
.row-list {
    display: flex;
    flex-direction: column;
    margin-top: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow-card);
}
.row-list-header:first-child {
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
}
.row-list-item:last-of-type {
    border-bottom-left-radius: var(--radius);
    border-bottom-right-radius: var(--radius);
    overflow: visible;
}
.row-list-header, .row-list-item {
    display: grid;
    grid-template-columns: 1fr 120px 80px;
    align-items: center;
}
.row-list-2col .row-list-header,
.row-list-2col .row-list-item {
    grid-template-columns: 1fr 1fr 70px 80px;
}
.row-list-3col .row-list-header,
.row-list-3col .row-list-item {
    grid-template-columns: 110px 1fr 1fr 120px 120px 80px 70px 90px 80px;
}
.row-list-header {
    font-size: 12.5px;
    color: var(--color-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}
.row-list-item {
    border-bottom: 1px solid var(--color-border);
}
.row-list-item:last-of-type { border-bottom: none; }
.row-list:has(.row-list-item:nth-of-type(even)) .row-list-item:nth-of-type(even) {
    background: var(--color-bg);
}
.row-list-header > *, .row-list-item > input, .row-list-item > select, .row-list-item > span {
    padding: 10px 14px;
    margin: 0;
}
.row-list-header > *:not(:last-child),
.row-list-item > *:not(:last-child) {
    border-right: 1px solid var(--color-border);
}
.row-list-count { font-size: 14px; }
.inline-input, .row-list-item select {
    border: none;
    background: transparent;
    font-size: 14px;
    width: 100%;
    font-family: inherit;
    border-radius: 0;
}
.inline-input:focus, .row-list-item select:focus {
    outline: none;
    background: var(--color-primary-soft);
}
.row-list-item > button { margin: 6px 10px; }
.row-list-item.row-closed { opacity: 0.6; }

/* --- Tag select widget (Odoo-style chip picker) --- */
.tag-select {
    position: relative;
    padding: 8px 12px !important;
}
.tag-select-source { display: none; }
.tag-select-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}
.tag-select-chips:empty { margin-bottom: 0; }
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--color-primary-soft);
    color: var(--color-primary-dark);
    padding: 3px 6px 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.tag-chip button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-primary-dark);
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    opacity: 0.65;
}
.tag-chip button:hover { opacity: 1; }
.tag-select-input-wrap { position: relative; }
.tag-select-input {
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 13px;
    width: 100%;
    font-family: inherit;
}
.tag-select-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.tag-select-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-card);
    max-height: 180px;
    overflow-y: auto;
    z-index: 300;
}
.tag-select-dropdown.open { display: block; }
.tag-select-option {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
}
.tag-select-option:hover { background: var(--color-bg); }
.tag-select-empty {
    padding: 8px 12px;
    font-size: 12px;
    color: var(--color-muted);
}

/* --- Buttons: rounded pill style --- */
.btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--color-bg); }
.btn:active { transform: scale(0.98); }
.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }

/* --- Forms --- */
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--color-muted); font-weight: 600; }
.field input, .field select, .field textarea {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 14px;
    font-family: inherit;
    width: 100%;
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.field input[type="checkbox"] {
    width: auto;
    flex: 0 0 auto;
}
.field-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 10px;
}
.field-row .field { flex: 1; min-width: 140px; margin-bottom: 0; }
.field-row input[type=text] {
    flex: 1;
    min-width: 120px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    font-size: 14px;
    font-family: inherit;
}
.field-row input[type=text]:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

/* --- File input, styled to match the rest of the buttons --- */
input[type="file"] {
    font-size: 14px;
    font-family: inherit;
    color: var(--color-muted);
}
input[type="file"]::file-selector-button,
input[type="file"]::-webkit-file-upload-button {
    padding: 9px 18px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    margin-inline-end: 10px;
}
input[type="file"]::file-selector-button:hover,
input[type="file"]::-webkit-file-upload-button:hover {
    background: var(--color-bg);
}
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 14px; }

/* --- Alerts --- */
.alert { padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 14px; font-weight: 500; }
.alert-error { background: #FEE2E8; color: #9F1239; }
.alert-success { background: #DCFCE7; color: #166534; }
.alert-info { background: var(--color-primary-soft); color: var(--color-primary-dark); }

/* --- Login page --- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, var(--color-primary-soft) 0%, var(--color-bg) 60%);
}
.login-card {
    background: var(--color-card);
    border-radius: 20px;
    padding: 32px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 12px 40px rgba(30, 27, 58, 0.12);
}
.login-card h1 { font-size: 20px; margin-top: 0; }

/* --- Tabs --- */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 14px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    padding: 4px;
    width: fit-content;
}
.tab {
    padding: 7px 16px;
    text-decoration: none;
    color: var(--color-muted);
    border-radius: var(--radius-pill);
    font-size: 14px;
    font-weight: 600;
}
.tab.active { color: #fff; background: var(--color-primary); }

/* --- Toolbar --- */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}
.toolbar select {
    padding: 8px 12px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border);
    background: #fff;
    font-size: 13px;
    font-family: inherit;
    color: var(--color-text);
}
.toolbar select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.search-input {
    padding: 8px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border);
    font-size: 13px;
    font-family: inherit;
    min-width: 180px;
}
.search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

/* --- Task list / cards --- */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    text-decoration: none;
    color: var(--color-text);
    display: block;
    border-inline-start: 4px solid var(--color-border);
    box-shadow: var(--shadow-card);
    transition: transform 0.1s ease, box-shadow 0.15s ease;
}
.task-card:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(30, 27, 58, 0.09); }
.task-card.status-new { border-inline-start-color: #9ca3af; }
.task-card.status-in_progress { border-inline-start-color: var(--color-primary); }
.task-card.status-done { border-inline-start-color: #D97706; }
.task-card.status-finished { border-inline-start-color: var(--color-success); }
.task-card.overdue { border-inline-start-color: var(--color-danger); background: #FFF5F7; }

.task-card-top { display: flex; justify-content: space-between; gap: 8px; }
.task-title { font-weight: 600; }
.task-card-meta {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--color-muted);
    margin-top: 4px;
    flex-wrap: wrap;
    gap: 4px;
}
.task-card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 13px;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    background: var(--color-bg);
    color: var(--color-text);
}
.badge-type { background: #EDE9FE; color: #5B21B6; }
.badge-status { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.badge-active { background: #DCFCE7; color: #166534; }
.badge-inactive { background: #FEE2E8; color: #9F1239; }

.btn-danger { border-color: #FBC7D3; color: #9F1239; }
.btn-danger:hover { background: #FEE2E8; }
.btn-success { background: var(--color-success); border-color: var(--color-success); color: #fff; }
.btn-success:hover { background: #15803D; }

.text-danger { color: var(--color-danger); font-weight: 600; }
.empty-state { color: var(--color-muted); font-size: 14px; text-align: center; padding: 24px 0; }

/* --- Task detail page --- */
.task-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.task-detail-header h1 { font-size: 21px; margin: 0; letter-spacing: -0.2px; }
.task-header-actions { display: flex; align-items: center; gap: 10px; }
.inline-form { display: inline-block; }

.status-pill-new { background: var(--color-bg); color: #4b5563; }
.status-pill-in_progress { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.status-pill-done { background: #FEF3C7; color: #92400E; }
.status-pill-finished { background: #DCFCE7; color: #166534; }

/* --- Chat-style activity log --- */
.chat-thread {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
    max-height: 420px;
    overflow-y: auto;
    padding: 4px 2px;
}
.chat-message {
    max-width: 80%;
    background: var(--color-bg);
    border-radius: 16px;
    padding: 9px 14px;
    align-self: flex-start;
}
.chat-message.own {
    align-self: flex-end;
    background: var(--color-primary);
    color: #fff;
}
.chat-message.system {
    background: transparent;
    border: 1px dashed var(--color-border);
    color: var(--color-muted);
    font-size: 13px;
    max-width: 100%;
    align-self: stretch;
    text-align: center;
    border-radius: var(--radius-sm);
}
.chat-message-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    margin-bottom: 3px;
}
.chat-message.own .chat-message-top { color: #ffffff; opacity: 0.95; }
.chat-message.system.own {
    background: transparent;
    color: var(--color-muted);
}
.chat-message.system.own .chat-message-top {
    color: var(--color-muted);
    opacity: 1;
}
.chat-message-date { white-space: nowrap; }
.chat-message-body { font-size: 14px; word-break: break-word; }
.chat-composer { align-items: center; }
.task-detail-meta {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin: 14px 0;
    font-size: 14px;
    box-shadow: var(--shadow-card);
}
.task-detail-desc {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-card);
}

.card {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-card);
}
.card h2 { font-size: 16px; margin-top: 0; }

.attachment-list, .log-list { list-style: none; margin: 0 0 12px; padding: 0; }
.attachment-list li { padding: 8px 0; border-bottom: 1px solid var(--color-border); }
.attachment-list a { color: var(--color-primary); text-decoration: none; font-weight: 600; }

/* --- Upload progress bar --- */
.upload-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--color-bg);
    border-radius: var(--radius-pill);
    overflow: hidden;
    margin-bottom: 4px;
}
.upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--color-primary);
    border-radius: var(--radius-pill);
    transition: width 0.15s ease;
}

.log-item { padding: 10px 0; border-bottom: 1px solid var(--color-border); }
.log-item-top { display: flex; justify-content: space-between; font-size: 13px; }
.log-date { color: var(--color-muted); }
.log-item-body { margin-top: 4px; font-size: 14px; }

/* --- Responsive: tablet and up --- */
@media (min-width: 640px) {
    .task-detail-meta { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
    /* --- Compact nav buttons so they don't dominate the screen --- */
    .topbar {
        padding: 10px 12px;
        gap: 6px;
    }
    .topbar-left, .topbar-right {
        gap: 6px;
    }
    .admin-nav {
        gap: 4px;
    }
    .admin-nav .btn,
    .topbar-left > .btn,
    .topbar-right > .btn {
        padding: 5px 10px;
        font-size: 12px;
    }
    .brand { font-size: 15px; }
    .user-name { font-size: 12px; }
    .dropdown-menu { min-width: 150px; }

    /* --- Cards: less padding, content still readable --- */
    .card { padding: 12px; }
    .container { padding: 12px; }

    /* --- Row lists (Clients, Projects, Categories): fully stacked --- */
    .row-list-header { display: none; }
    .row-list-item {
        grid-template-columns: 1fr !important;
        gap: 2px;
        padding: 8px 0;
    }
    .row-list-item > * {
        border-right: none !important;
        border-bottom: 1px solid var(--color-border);
        padding: 8px 10px !important;
        width: 100%;
    }
    .row-list-item > *:last-child { border-bottom: none; }
    .row-list-item > button { margin: 4px 10px; width: calc(100% - 20px); }
    .tag-select { padding: 8px 10px !important; }

    /* --- Admin tables: smaller text, tighter cells --- */
    .admin-table { font-size: 13px; }
    .admin-table th, .admin-table td { padding: 6px 8px; }

    /* --- Forms: single column, full-width fields --- */
    .field-row { flex-direction: column; align-items: stretch; }
    .field-row .field { min-width: 0; }
}

@media (max-width: 480px) {
    .row-list-header, .row-list-item {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .row-list-header span:not(:first-child) { display: none; }
}

@media (min-width: 768px) {
    body { font-size: 16px; }
    .container { padding: 24px; }
}

/* --- Site footer --- */
.site-footer {
    margin-top: 24px;
    padding: 18px 20px;
    border-top: 1px solid var(--color-border);
    background: var(--color-card);
    flex-shrink: 0;
}
.site-footer-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 13px;
    color: var(--color-muted);
}
.site-footer-credit { font-weight: 600; }
