/* ================================================
   RAiS Scoping Assistant — Style
   Mobile-first, professional, restoration industry
   ================================================ */

:root {
    --brand: #1a5276;
    --brand-light: #2e86c1;
    --brand-dark: #0e2f44;
    --accent: #e67e22;
    --success: #27ae60;
    --danger: #c0392b;
    --warning: #f39c12;
    --bg: #f5f6fa;
    --surface: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #dce1e8;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ─── Screens ─────────────────────────────────── */

.screen { display: none; }
.screen.active { display: flex; }
#app-screen { flex-direction: column; min-height: 100vh; }
#login-screen { justify-content: center; align-items: center; min-height: 100vh; }

/* ─── Card / Auth ────────────────────────────── */

.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    margin: 1rem;
}

.logo-area {
    text-align: center;
    margin-bottom: 1.5rem;
}
.logo-area h1 {
    font-size: 2rem;
    color: var(--brand);
    letter-spacing: 2px;
}
.logo-area .subtitle {
    color: var(--text-light);
    font-size: 0.9rem;
}

/* ─── Tab Bar ────────────────────────────────── */

.tab-bar {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}
.tab {
    flex: 1;
    padding: 0.6rem;
    border: none;
    background: none;
    font-size: 0.95rem;
    color: var(--text-light);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
}
.tab.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
    font-weight: 600;
}

/* ─── Forms ──────────────────────────────────── */

.form { display: none; }
.form.active { display: block; }

.field {
    margin-bottom: 1rem;
}
.field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}
.field input, .field select, .field textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    color: var(--text);
    background: var(--surface);
    transition: var(--transition);
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none;
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(46,134,193,0.15);
}

/* ─── Buttons ────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}
.btn.primary:hover { background: var(--brand-dark); }
.btn.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn.tiny { padding: 0.15rem 0.4rem; font-size: 0.75rem; border-radius: 4px; line-height: 1; }
.btn.icon-only {
    padding: 0.3rem 0.5rem;
    border: none;
    background: none;
    color: rgba(255,255,255,0.8);
    font-size: 1.1rem;
    cursor: pointer;
}
.btn.icon-only:hover { color: #fff; }
.btn.icon {
    padding: 0.5rem;
    border: none;
    background: none;
    color: var(--text-light);
}
.btn.icon:hover { color: var(--brand); }
.btn.icon.recording { color: var(--danger); animation: pulse 1s infinite; }
.full-width { width: 100%; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ─── Header ─────────────────────────────────── */

#app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    background: var(--brand);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-brand {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 1px;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.user-name { font-size: 0.85rem; opacity: 0.9; }
#logout-btn {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}
#logout-btn:hover { background: rgba(255,255,255,0.25); }

/* ─── Main Layout ────────────────────────────── */

#app-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1rem;
    overflow-y: auto;
}
#sidebar h2 {
    font-size: 1rem;
    color: var(--text-light);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#content-area {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

/* ─── Status Filter ──────────────────────────── */

.status-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
}
.filter-chip {
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-light);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}
.filter-chip:hover { background: var(--bg); }
.filter-chip.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

/* ─── Status Badge ────────────────────────────── */

.status-badge {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    text-transform: capitalize;
    font-weight: 500;
}
.status-new { background: #eaf2f8; color: var(--brand); }
.status-estimate { background: #fef9e7; color: #b7950b; }
.status-demo { background: #fdedec; color: var(--danger); }
.status-drying { background: #e8f8f5; color: #1abc9c; }
.status-in_review { background: #f4ecf7; color: #8e44ad; }
.status-complete { background: #eafaf1; color: var(--success); }

/* ─── Status Select ──────────────────────────── */

.status-select {
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-light);
    background: var(--surface);
    cursor: pointer;
}
.status-select:focus {
    outline: none;
    border-color: var(--brand-light);
}

/* ─── Jobs List ───────────────────────────────── */

.list-group { margin-top: 0.75rem; }
.list-item {
    padding: 0.7rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 0.25rem;
}
.list-item:hover { background: var(--bg); }
.list-item.active { background: #eaf2f8; border-left: 3px solid var(--brand); }
.list-item .item-name {
    font-weight: 600;
    font-size: 0.9rem;
}
.list-item .item-meta {
    font-size: 0.75rem;
    color: var(--text-light);
}

/* ─── Empty State ────────────────────────────── */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-light);
}
.empty-state h2 { margin-bottom: 0.5rem; color: var(--text); }

.empty-hint {
    padding: 1rem;
    text-align: center;
    color: var(--text-light);
    font-size: 0.85rem;
    font-style: italic;
}

/* ─── View Toggle ────────────────────────────── */

.hidden { display: none !important; }

/* ─── Job View ───────────────────────────────── */

.job-header { margin-bottom: 1rem; }
.job-header h2 { font-size: 1.3rem; }
.job-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}
.job-meta span {
    font-size: 0.8rem;
    background: var(--bg);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    color: var(--text-light);
}
.job-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

/* ─── Job Body (Rooms + Chat) ─────────────────── */

.job-body {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

/* ─── Rooms Panel ─────────────────────────────── */

.rooms-panel {
    width: 260px;
    min-width: 200px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.75rem;
}
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.panel-header h3 {
    font-size: 0.95rem;
}

.room-add-form {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
    align-items: center;
}
.room-add-form input {
    flex: 1;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
}
.room-add-form button {
    flex-shrink: 0;
}

.rooms-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.room-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    transition: var(--transition);
}
.room-item:hover { background: var(--bg); }

.room-info {
    display: flex;
    flex-direction: column;
}
.room-name {
    font-size: 0.85rem;
    font-weight: 600;
}
.room-type {
    font-size: 0.7rem;
    color: var(--text-light);
}
.room-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.room-items {
    font-size: 0.75rem;
    color: var(--text-light);
}
.room-delete {
    color: var(--danger);
    border-color: var(--danger);
    background: transparent;
    font-size: 1rem;
    line-height: 1;
    padding: 0 0.3rem;
}
.room-delete:hover {
    background: var(--danger);
    color: #fff;
}

/* ─── Chat ────────────────────────────────────── */

#chat-container {
    flex: 1;
    min-width: 0;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    height: 400px;
}

.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.msg {
    max-width: 80%;
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
}
.msg.user {
    align-self: flex-end;
    background: var(--brand);
    color: #fff;
    border-bottom-right-radius: 2px;
}
.msg.assistant {
    align-self: flex-start;
    background: #eaf2f8;
    color: var(--text);
    border-bottom-left-radius: 2px;
}
.msg .msg-role {
    font-size: 0.7rem;
    text-transform: uppercase;
    opacity: 0.7;
    margin-bottom: 0.15rem;
}

.chat-input-area {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    border-top: 1px solid var(--border);
    gap: 0.4rem;
}
#chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}
#chat-input:focus {
    outline: none;
    border-color: var(--brand-light);
}

/* ─── Progress ───────────────────────────────── */

.progress-area {
    margin-top: 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}
.progress-area h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
}
#phase-indicators {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.phase-badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    background: var(--bg);
    color: var(--text-light);
}
.phase-badge.active {
    background: var(--brand);
    color: #fff;
}
.phase-badge.complete {
    background: var(--success);
    color: #fff;
}

/* ─── Review View ─────────────────────────────── */

.review-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}
.review-header h2 { font-size: 1.3rem; }

.review-summary {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.review-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.review-stat-num {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--brand);
}
.review-stat-label {
    font-size: 0.75rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.review-warning {
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #fef9e7;
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: #7d6608;
}

.review-rooms {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.review-room {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
}
.review-room.empty {
    border-left: 3px solid var(--warning);
}

.review-room-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}
.review-room-name {
    font-weight: 600;
    font-size: 1rem;
}
.review-room-type {
    font-size: 0.8rem;
    color: var(--text-light);
}
.review-room-badge {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    margin-left: auto;
}
.review-room-badge.has-items {
    background: #eafaf1;
    color: var(--success);
}
.review-room-badge.no-items {
    background: #fef9e7;
    color: var(--warning);
}

.review-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.review-table th {
    text-align: left;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-light);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.3px;
}
.review-table td {
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid #f0f0f0;
}
.review-table tr:hover td { background: var(--bg); }

.review-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
    justify-content: center;
}

/* ─── Profile & Team View ────────────────────── */

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}
.profile-header h2 { font-size: 1.3rem; }

.profile-section {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.profile-section h3 {
    font-size: 0.95rem;
    color: var(--brand);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.profile-info { }

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    font-size: 0.9rem;
}
.info-row span:first-child {
    color: var(--text-light);
    font-weight: 500;
}
.info-row span:last-child {
    font-weight: 600;
}

.team-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.team-member {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius);
    transition: var(--transition);
}
.team-member:hover { background: var(--bg); }

.member-initials {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}
.member-name {
    font-weight: 600;
    font-size: 0.9rem;
}
.member-role {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-left: auto;
}
.member-status {
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}
.member-status.active { background: #eafaf1; color: var(--success); }
.member-status.inactive { background: var(--bg); color: var(--text-light); }

/* ─── Modal ──────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}
.modal h3 { margin-bottom: 1rem; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ─── Toast ──────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--brand-dark);
    color: #fff;
    padding: 0.6rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    z-index: 300;
    opacity: 0;
    transition: opacity 0.3s;
}
.toast.visible { opacity: 1; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }


/* ─── Brand Icon ─────────────────────────────── */

.brand-icon {
    vertical-align: middle;
    margin-right: 6px;
}

.brand-icon-sm {
    vertical-align: middle;
    margin-right: 4px;
}

.header-brand svg {
    vertical-align: middle;
}

.logo-area h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
}

/* ─── Role Badges ─────────────────────────────── */

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.role-admin { background: #e8f5e9; color: #2e7d32; }
.role-estimator { background: #e3f2fd; color: #1565c0; }
.role-tech { background: #fff3e0; color: #e65100; }
.role-viewer { background: #f3e5f5; color: #7b1fa2; }

/* ─── Invite Banner ──────────────────────────── */

.invite-banner {
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.invite-banner p {
    margin: 0;
    font-size: 0.9rem;
    color: #2e7d32;
}

.invite-banner strong {
    color: #1b5e20;
}

/* ─── Invite Section ──────────────────────────── */

.invite-section {
    margin-top: 1rem;
}

.invite-section.hidden {
    display: none;
}

.invite-form-inline {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.invite-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.invite-info {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.pending-invites h4 {
    margin: 0.75rem 0 0.25rem 0;
    font-size: 0.85rem;
    color: var(--text-light);
}

#invite-form .field {
    margin-bottom: 0.5rem;
}

/* ─── Role Select (Team) ─────────────────────── */

.role-select {
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.75rem;
    background: var(--surface);
    cursor: pointer;
}

/* ─── Hidden utility ─────────────────────────── */

#company-fields.hidden {
    display: none;
}

/* ─── Responsive ─────────────────────────────── */

@media (max-width: 768px) {
    #app-main { flex-direction: column; }
    #sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 200px;
    }
    .job-body { flex-direction: column; }
    .rooms-panel { width: 100%; }
    #chat-container { height: 350px; }
    .card { padding: 1.5rem; }
    .msg { max-width: 90%; }
    .review-summary { gap: 1rem; }
    .review-stat-num { font-size: 1.25rem; }
    .review-table { font-size: 0.75rem; }
    .team-member { gap: 0.5rem; }
}