:root {
    --primary: #007A3D;
    --primary-light: #009947;
    --primary-bg: #e6f2eb;
    --green: #009947;
    --green-bg: #e6f2eb;
    --accent: #d4af37;
    --orange: #e67e22;
    --orange-bg: #fef0e4;
    --purple: #8e44ad;
    --teal: #16a085;
    --red: #e74c3c;
    --text-dark: #1a2a1e;
    --text-medium: #4a6a5a;
    --text-light: #7a9a87;
    --bg: #f2f7f4;
    --card: #ffffff;
    --border: #d8ebe0;
    --shadow: 0 1px 4px rgba(0, 90, 46, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text-dark);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

a { color: inherit; }

.view { min-height: 100vh; }
.hidden { display: none !important; }

/* ── LOGIN ─────────────────────────────────────────────────────────────────── */

.login-container {
    max-width: 420px;
    margin: 0 auto;
    padding: 40px 20px 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    min-height: 100vh;
    justify-content: center;
}

.login-logo { text-align: center; }

.logo-img-wrap {
    background: white;
    border-radius: 16px;
    padding: 14px 20px;
    display: inline-block;
    margin: 0 auto 16px;
    box-shadow: 0 4px 20px rgba(0, 122, 61, 0.18);
    border: 1px solid var(--border);
}

.login-logo-img {
    width: 180px;
    height: auto;
    display: block;
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-dark);
}

.login-logo p {
    font-size: 14px;
    color: var(--text-medium);
    margin-top: 4px;
}

/* ── LOGIN CREDENTIALS ─────────────────────────────────────────────────────── */

.login-credentials {
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: white;
    overflow: hidden;
}

.cred-header {
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-medium);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cred-arrow { transition: transform 0.2s; margin-left: auto; }

.login-credentials.open .cred-arrow { transform: rotate(180deg); }

.cred-body {
    display: none;
    border-top: 1px solid var(--border);
    padding: 10px 14px;
}

.login-credentials.open .cred-body { display: block; }

.cred-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.cred-table th {
    text-align: left;
    color: var(--text-light);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 6px 6px;
}

.cred-table td {
    padding: 5px 6px;
    color: var(--text-dark);
    border-top: 1px solid var(--border);
}

.cred-table td:nth-child(2),
.cred-table td:nth-child(3) {
    font-family: monospace;
    font-size: 13px;
    color: var(--primary);
    font-weight: 600;
}

/* ── CARD ──────────────────────────────────────────────────────────────────── */

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    width: 100%;
}

/* ── HEADER ────────────────────────────────────────────────────────────────── */

.app-header {
    background: var(--primary);
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 90, 46, 0.25);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    max-width: 700px;
    margin: 0 auto;
    gap: 8px;
}

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

.header-logo-img {
    height: 28px;
    width: auto;
    filter: brightness(0) invert(1);
    display: block;
}

.header-title {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
}

.header-center {
    font-weight: 600;
    font-size: 15px;
    flex: 1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 4px;
}

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

.user-chip { font-size: 13px; opacity: 0.85; white-space: nowrap; }

/* ── PAGE CONTENT ──────────────────────────────────────────────────────────── */

.page-content {
    max-width: 700px;
    margin: 0 auto;
    padding: 16px 16px 48px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
}

.page-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-dark);
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-light);
    padding: 6px 2px 0;
}

/* ── FRANCHISEE LIST ───────────────────────────────────────────────────────── */

.franchisee-list { display: flex; flex-direction: column; gap: 10px; }

.franchisee-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s;
    border-left: 4px solid var(--primary);
}

.franchisee-card:active { transform: scale(0.98); box-shadow: none; }
.franchisee-card.complete { border-left-color: var(--green); }

.fc-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.fc-name { font-weight: 600; font-size: 16px; color: var(--text-dark); }
.fc-company { font-size: 13px; color: var(--text-medium); margin-top: 2px; }
.fc-city { font-size: 12px; color: var(--text-light); margin-top: 2px; }

.progress-pill {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    white-space: nowrap;
    flex-shrink: 0;
}

.progress-pill.complete { background: var(--green-bg); color: #1e8449; }
.progress-pill.in-progress { background: var(--primary-bg); color: var(--primary); }
.progress-pill.not-started { background: #f0f4f8; color: var(--text-light); }

.mini-progress {
    height: 5px;
    background: #e1e8ef;
    border-radius: 5px;
    overflow: hidden;
}

.mini-progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--primary), #00c850);
    border-radius: 5px;
    transition: width 0.4s ease;
}

/* ── DETAIL INFO ───────────────────────────────────────────────────────────── */

.detail-info-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
}

.detail-info-item label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-light);
    font-weight: 700;
}

.detail-info-item span {
    display: block;
    font-size: 14px;
    color: var(--text-dark);
    font-weight: 500;
    margin-top: 3px;
}

.detail-info-item a { color: var(--primary); text-decoration: none; }
.detail-info-item a:hover { text-decoration: underline; }
.detail-info-item.full-width { grid-column: 1 / -1; }

/* ── PROGRESS ──────────────────────────────────────────────────────────────── */

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
}

.progress-text { font-size: 14px; color: var(--primary); font-weight: 700; }

.progress-bar-outer {
    height: 8px;
    background: #e1e8ef;
    border-radius: 8px;
    overflow: hidden;
}

.progress-bar-inner {
    height: 100%;
    background: linear-gradient(to right, var(--primary), #00c850);
    border-radius: 8px;
    transition: width 0.5s ease;
    min-width: 0;
}

/* ── STEP CARDS ────────────────────────────────────────────────────────────── */

.step-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    user-select: none;
    transition: background 0.1s;
}

.step-header:active { background: #f8fafc; }

.step-number {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    transition: background 0.3s;
}

.step-number.done { background: var(--green); color: white; }
.step-number.pending { background: #e1e8ef; color: var(--text-medium); }

.step-info { flex: 1; min-width: 0; }

.step-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-dark);
    line-height: 1.3;
}

.step-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 3px;
}

.step-expand {
    font-size: 14px;
    color: var(--text-light);
    flex-shrink: 0;
    transition: transform 0.22s ease;
    line-height: 1;
}

.step-expand.open { transform: rotate(180deg); }

.step-body {
    border-top: 1px solid var(--border);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: fadeIn 0.15s ease;
}

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

.step-description {
    font-size: 13px;
    color: var(--text-medium);
    line-height: 1.6;
}

.step-completion-info {
    background: var(--green-bg);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 13px;
    color: #1e8449;
    line-height: 1.5;
}

.completion-by { font-weight: 700; }

.step-notes-text {
    font-size: 13px;
    color: var(--text-medium);
    font-style: italic;
    margin-top: 4px;
    opacity: 0.9;
}

.step-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── DOCUMENTS ─────────────────────────────────────────────────────────────── */

.step-docs { display: flex; flex-direction: column; gap: 6px; }

.step-docs-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    margin-bottom: 2px;
}

.doc-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-bg);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.doc-icon { font-size: 18px; flex-shrink: 0; }

.doc-name {
    flex: 1;
    font-size: 13px;
    color: var(--primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
}

.doc-name:hover { text-decoration: underline; }
.doc-meta { font-size: 11px; color: var(--text-light); white-space: nowrap; }

.upload-btn-label {
    cursor: pointer;
}

/* ── CHAT ──────────────────────────────────────────────────────────────────── */

.chat-card { padding: 0; overflow: hidden; }

.chat-messages {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 360px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.chat-message {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.chat-bubble-wrap { flex: 1; min-width: 0; }

.chat-bubble-header {
    font-size: 11px;
    color: var(--text-light);
    margin-bottom: 3px;
}

.chat-bubble {
    background: #f0f4f8;
    border-radius: 0 10px 10px 10px;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.45;
    color: var(--text-dark);
    display: inline-block;
    max-width: 100%;
    word-break: break-word;
}

.chat-message.own { flex-direction: row-reverse; }

.chat-message.own .chat-bubble {
    background: var(--primary);
    color: white;
    border-radius: 10px 0 10px 10px;
}

.chat-message.own .chat-bubble-wrap {
    align-items: flex-end;
    display: flex;
    flex-direction: column;
}

.chat-message.own .chat-bubble-header { text-align: right; }

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}

.chat-input {
    flex: 1;
    border: 1.5px solid var(--border);
    border-radius: 24px;
    padding: 9px 14px;
    font-size: 15px;
    outline: none;
    background: white;
    color: var(--text-dark);
    font-family: inherit;
    transition: border-color 0.2s;
}

.chat-input:focus { border-color: var(--primary); }

.chat-send-btn {
    width: 42px !important;
    height: 42px !important;
    border-radius: 50% !important;
    padding: 0 !important;
    font-size: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── BUTTONS ───────────────────────────────────────────────────────────────── */

.btn {
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 10px 16px;
    transition: background 0.14s, opacity 0.14s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.btn:active { opacity: 0.78; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: #229954; }
.btn-danger { background: var(--red); color: white; }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text-dark); }
.btn-outline-primary { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-outline-danger { background: transparent; border: 1.5px solid var(--red); color: var(--red); }
.btn-ghost { background: transparent; color: white; opacity: 0.88; }
.btn-ghost:hover { opacity: 1; }
.btn-ghost-dark { background: transparent; color: var(--text-medium); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; }

/* ── FORMS ─────────────────────────────────────────────────────────────────── */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-medium);
}

.form-group input,
.form-group select,
.textarea {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    font-size: 15px;
    outline: none;
    background: white;
    color: var(--text-dark);
    width: 100%;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.textarea:focus { border-color: var(--primary); }

.textarea { resize: vertical; line-height: 1.5; }

.error-msg {
    background: #fdf0ef;
    border: 1px solid #f1948a;
    color: #c0392b;
    border-radius: var(--radius-sm);
    padding: 10px 13px;
    font-size: 13px;
    margin-bottom: 10px;
}

/* ── MODAL ─────────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.modal {
    background: var(--card);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 20px 20px 36px;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    animation: slideUp 0.22s ease;
}

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

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

.modal-header h3 { font-size: 18px; font-weight: 700; color: var(--text-dark); }
.modal-header .btn-ghost-dark { font-size: 20px; }

/* ── MY TURN BANNER ───────────────────────────────────────────────────────── */

.my-turn-banner {
    background: linear-gradient(135deg, var(--primary), #009947);
    color: white;
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    box-shadow: 0 2px 12px rgba(0, 122, 61, 0.28);
}

.banner-icon { font-size: 22px; flex-shrink: 0; padding-top: 1px; }

.banner-content { flex: 1; min-width: 0; }

.banner-content strong { font-size: 14px; display: block; margin-bottom: 8px; letter-spacing: 0.2px; }

.banner-items { display: flex; flex-direction: column; gap: 5px; }

.banner-item {
    font-size: 13px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    transition: background 0.12s;
    display: block;
    line-height: 1.4;
}

.banner-item:active { background: rgba(255, 255, 255, 0.3); }

/* ── DRAN BADGE ────────────────────────────────────────────────────────────── */

.dran-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 12px;
    margin-top: 5px;
}

.franchisee-card.dran { border-left-color: var(--primary); }

/* ── STEP STATES ───────────────────────────────────────────────────────────── */

.step-card.step-locked { opacity: 0.5; }

.step-card.step-locked .step-header { cursor: default; }

.step-card.step-my-turn {
    border: 2px solid var(--primary);
    box-shadow: 0 2px 14px rgba(0, 122, 61, 0.16);
}

.step-card.step-my-turn .step-header { background: var(--primary-bg); }

.step-meta-mine { color: var(--primary) !important; font-weight: 600; }

.step-meta-locked { color: var(--text-light); font-style: italic; }

.step-locked-info {
    font-size: 13px;
    color: var(--text-light);
    font-style: italic;
    background: #f8faf9;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

/* ── SYSTEM MESSAGE ────────────────────────────────────────────────────────── */

.chat-message.system { justify-content: center; }

.system-msg {
    background: var(--primary-bg);
    color: var(--primary);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    border: 1px solid rgba(0, 122, 61, 0.18);
    max-width: 90%;
}

/* ── EMPTY STATE ───────────────────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 36px 16px;
    color: var(--text-medium);
}

.empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; line-height: 1.6; }

/* ── TOAST ─────────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a2332;
    color: white;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    z-index: 999;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    animation: toastIn 0.2s ease;
    white-space: nowrap;
}

@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── RESPONSIVE ────────────────────────────────────────────────────────────── */

@media (min-width: 560px) {
    .modal-overlay { align-items: center; }
    .modal { border-radius: var(--radius); max-width: 520px; max-height: 85vh; animation: fadeIn 0.18s ease; }
    .detail-info-card { grid-template-columns: 1fr 1fr 1fr; }
}
