/* SMSFonen – modern UI, teal/slate palette, app shell, dark mode */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --bg-header: rgba(255, 255, 255, 0.85);
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #0f766e;
    --primary-hover: #0d9488;
    --primary-light: #ccfbf1;
    --primary-from: #0d9488;
    --primary-to: #14b8a6;
    --accent: #0ea5e9;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-light: #fef2f2;
    --success-bg: #ecfdf5;
    --success-border: #10b981;
    --success-text: #065f46;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-pill: 999px;
    --radius-xl: 20px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 10px 40px -10px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 20px 50px -15px rgba(0, 0, 0, 0.15);
    --recipient-bg: #f8fafc;
    --recipient-border: #e2e8f0;
    --header-height: 56px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-page: #0f172a;
        --bg-card: #1e293b;
        --bg-header: rgba(15, 23, 42, 0.9);
        --text: #f1f5f9;
        --text-muted: #94a3b8;
        --border: #334155;
        --primary-light: #134e4a;
        --danger-light: #450a0a;
        --success-bg: #052e16;
        --success-border: #166534;
        --success-text: #86efac;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 10px 40px -10px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 20px 50px -15px rgba(0, 0, 0, 0.5);
        --recipient-bg: #1e293b;
        --recipient-border: #334155;
    }
}

[data-theme="dark"] {
    --bg-page: #0f172a;
    --bg-card: #1e293b;
    --bg-header: rgba(15, 23, 42, 0.9);
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --primary-light: #134e4a;
    --danger-light: #450a0a;
    --success-bg: #052e16;
    --success-border: #166534;
    --success-text: #86efac;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 40px -10px rgba(0, 0, 0, 0.4);
    --recipient-bg: #1e293b;
    --recipient-border: #334155;
}

[data-theme="light"] {
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --bg-header: rgba(255, 255, 255, 0.85);
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary-light: #ccfbf1;
    --recipient-bg: #f8fafc;
    --recipient-border: #e2e8f0;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg-page);
    padding: 0;
}

/* ----- App shell (admin + superadmin) ----- */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--bg-header);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    color: var(--text);
    text-decoration: none;
}

.app-header__brand-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.app-header__group {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--primary);
    background: var(--primary-light);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-pill);
}

.app-header__actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* Icon-only theme toggle in header */
.app-header__theme-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.app-header__theme-btn:hover {
    border-color: var(--text-muted);
    background: var(--bg-page);
}

.app-header__theme-btn .theme-toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-header .theme-toggle-wrap {
    margin-bottom: 0;
}

.app-header .theme-toggle-pill {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.app-header .fcf-btn-logout {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    border-radius: var(--radius-pill);
}

/* Header menu (dropdown) – frees space on mobile */
.app-header__menu {
    position: relative;
}

.app-header__menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.app-header__menu-btn:hover {
    border-color: var(--text-muted);
    background: var(--bg-page);
}

.app-header__menu-btn[aria-expanded="true"] {
    border-color: var(--primary);
    background: var(--primary-light);
}

.app-header__dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.35rem;
    min-width: 200px;
    padding: 0.35rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 150;
}

.app-header__dropdown[hidden] {
    display: none;
}

.app-header__dropdown-item {
    display: block;
    width: 100%;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    text-align: left;
    text-decoration: none;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.app-header__dropdown-item:hover {
    background: var(--bg-page);
}

.app-header__dropdown-item.logout {
    color: var(--danger);
}

.app-header__dropdown-item.logout:hover {
    background: var(--danger-light);
}

.app-main {
    flex: 1;
    padding: 1.5rem 1.25rem;
    margin: 0 auto;
    width: 100%;
    max-width: 640px;
    animation: contentIn 0.4s ease-out;
}

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

/* ----- Layout (standalone pages like login use .fcf-body) ----- */
.fcf-body {
    margin: 0 auto;
    max-width: 640px;
    padding: 1.5rem 1.25rem;
    animation: contentIn 0.4s ease-out;
}

/* When inside app-shell, .fcf-body is not used; app-main wraps content */
.app-main .page-title {
    margin-top: 0;
}

/* ----- Cards ----- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card:last-child {
    margin-bottom: 0;
}

/* ----- Typography ----- */
.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.35rem;
    letter-spacing: -0.03em;
}

.page-subtitle {
    font-size: 0.95rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-label::before {
    content: '';
    width: 3px;
    height: 0.9rem;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--primary-from), var(--primary-to));
}

/* ----- Alerts ----- */
.alert {
    padding: 1rem 1.25rem 1rem 3rem;
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    position: relative;
    font-size: 0.95rem;
    animation: contentIn 0.35s ease-out;
}

.alert .closebtn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.15s;
}

.alert .closebtn:hover {
    color: var(--danger);
}

.alert.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border-color: rgba(220, 38, 38, 0.4);
}

/* ----- Forms ----- */
.fcf-form-class {
    margin-bottom: 0;
}

.fcf-form-group {
    margin-bottom: 1.15rem;
}

.fcf-form-group:last-child {
    margin-bottom: 0;
}

.fcf-label {
    display: block;
    margin-bottom: 0.45rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.fcf-input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.fcf-form-control {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.fcf-form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.fcf-form-control::placeholder {
    color: var(--text-muted);
}

select.fcf-form-control {
    cursor: pointer;
    appearance: auto;
}

textarea.fcf-form-control {
    min-height: 120px;
    resize: vertical;
}

/* ----- Buttons ----- */
.fcf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.65rem 1.1rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.fcf-btn:active {
    transform: scale(0.98);
}

.fcf-btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--primary-from) 0%, var(--primary-to) 100%);
    box-shadow: 0 2px 8px rgba(13, 148, 136, 0.35);
}

.fcf-btn-primary:hover {
    filter: brightness(1.08);
    box-shadow: 0 4px 14px rgba(13, 148, 136, 0.4);
    transform: translateY(-1px);
}

.fcf-btn-glow {
    box-shadow: 0 4px 16px rgba(13, 148, 136, 0.4);
}

.fcf-btn-glow:hover {
    box-shadow: 0 6px 24px rgba(13, 148, 136, 0.45);
}

.fcf-btn-logout {
    color: #fff;
    background: var(--danger);
}

.fcf-btn-logout:hover {
    background: var(--danger-hover);
    transform: translateY(-1px);
}

.fcf-btn-lg {
    padding: 0.8rem 1.35rem;
    font-size: 1rem;
}

.fcf-btn-block {
    display: flex;
    width: 100%;
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-update {
    background: linear-gradient(135deg, var(--primary-from) 0%, var(--primary-to) 100%);
    color: #fff;
}

.btn-update:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-remove {
    background: var(--danger-light);
    color: var(--danger);
}

.btn-remove:hover {
    background: var(--danger);
    color: #fff;
    transform: translateY(-1px);
}

/* ----- Recipient list (sleek) ----- */
.recipient-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.recipient-list__header {
    display: grid;
    grid-template-columns: 5.5rem 1fr 7.5rem 5.5rem;
    gap: 0.5rem;
    align-items: center;
    padding: 0.4rem 0.75rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.recipient-list__header.recipient-list__header--no-subgroup {
    grid-template-columns: 5.5rem 1fr 5rem;
}

.recipient-item {
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s ease;
}

.recipient-item:last-child {
    border-bottom: none;
}

.recipient-item:hover {
    background: var(--recipient-bg);
}

.recipient-item form {
    display: grid;
    grid-template-columns: 5.5rem 1fr 5rem;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    width: 100%;
}

.recipient-item.recipient-item--has-subgroup form {
    grid-template-columns: 5.5rem 1fr 7.5rem 5rem;
}

.recipient-item .recipient-phone {
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    font-size: 0.875rem;
}

.recipient-item input[type="text"] {
    min-width: 0;
    padding: 0.4rem 0.55rem;
    font-size: 0.875rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text);
}

.recipient-item input[type="text"]:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-light);
}

.recipient-item select {
    padding: 0.4rem 0.55rem;
    font-size: 0.875rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    min-width: 0;
    background: var(--bg-card);
    color: var(--text);
}

.recipient-item .actions {
    display: flex;
    gap: 0.35rem;
    justify-self: end;
}

.recipient-item .btn-sm {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
    min-width: 2.1rem;
}

.recipient-item .btn-update {
    padding: 0.3rem 0.6rem;
}

.recipient-item .btn-remove {
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    line-height: 1;
    min-width: 2.1rem;
}

/* ----- User list (superadmin) ----- */
.user-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: background 0.15s;
}

.user-item:hover {
    background: var(--recipient-bg);
}

.user-item:last-child {
    border-bottom: none;
}

.user-item label {
    cursor: pointer;
    flex: 1;
    margin: 0;
}

.user-item input[type="radio"] {
    margin-right: 0.5rem;
    accent-color: var(--primary);
}

/* ----- Empty state ----- */
.empty-hint {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin: 0;
    padding: 2rem 1.5rem;
    text-align: center;
}

.empty-hint::before {
    content: '📭 ';
    font-size: 1.5rem;
}

/* ----- Theme toggle ----- */
.theme-toggle-wrap {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.75rem;
}

.theme-toggle {
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.85rem;
    cursor: pointer;
    transition: color 0.2s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--text-muted);
    box-shadow: var(--shadow);
}

.theme-toggle-pill {
    border-radius: var(--radius-pill);
    padding: 0.5rem 1rem;
}

.theme-toggle-icon {
    font-size: 1rem;
    line-height: 1;
}

.theme-toggle-pill[data-theme="dark"] .theme-toggle-icon[data-icon="sun"] {
    display: none;
}

.theme-toggle-pill[data-theme="light"] .theme-toggle-icon[data-icon="moon"] {
    display: none;
}

.theme-toggle-label {
    font-weight: 500;
}

/* ----- Login page ----- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    gap: 1.5rem;
}

.login-hero {
    text-align: center;
    animation: contentIn 0.5s ease-out;
}

.login-hero-icon {
    font-size: 3.5rem;
    margin-bottom: 0.5rem;
    line-height: 1;
    filter: drop-shadow(0 4px 12px rgba(13, 148, 136, 0.2));
}

.login-title {
    font-size: 2.1rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    margin: 0 0 0.25rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-to) 55%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-tagline {
    font-size: 1rem;
    color: var(--text-muted);
    margin: 0;
    font-weight: 500;
}

.login-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0 0 1.25rem;
}

.login-card {
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

/* ----- Modal ----- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(6px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease-out;
}

.modal-overlay.is-open {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    padding: 1.5rem;
    max-width: 420px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(-8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal .section-label {
    margin-top: 0;
}

/* ----- Focus ----- */
.fcf-btn:focus-visible,
.fcf-form-control:focus-visible,
.theme-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ----- Larger screens: wider shell, bigger header and content ----- */
@media (min-width: 521px) {
    .app-header {
        height: 72px;
        padding: 0 2rem;
        gap: 1.5rem;
    }
    .app-header__brand {
        font-size: 1.4rem;
        gap: 0.9rem;
    }
    .app-header__brand-icon {
        font-size: 2rem;
    }
    .app-header__group {
        font-size: 0.9rem;
        padding: 0.45rem 0.9rem;
    }
    .app-header__actions {
        gap: 0.6rem;
    }
    .app-header__theme-btn,
    .app-header__menu-btn {
        width: 3rem;
        height: 3rem;
        font-size: 1.35rem;
    }
    .app-header__dropdown {
        min-width: 220px;
        padding: 0.4rem;
    }
    .app-header__dropdown-item {
        padding: 0.7rem 1rem;
        font-size: 0.95rem;
    }
    .app-main,
    .fcf-body {
        max-width: 720px;
        padding: 1.75rem 1.5rem;
    }
    .app-main .page-title {
        font-size: 1.65rem;
    }
    .app-main .page-subtitle {
        font-size: 1rem;
    }
    .card {
        padding: 1.75rem;
        margin-bottom: 1.5rem;
    }
    .section-label {
        font-size: 0.72rem;
        margin-bottom: 1.1rem;
    }
}

/* ----- Mobile ----- */
@media (max-width: 520px) {
    body {
        padding: 0;
    }
    .app-header {
        padding: 0 1rem;
        gap: 0.5rem;
    }
    .app-header__group {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
    }
    .app-main,
    .fcf-body {
        padding: 1.25rem 1rem;
    }
    .login-title {
        font-size: 1.85rem;
    }
    .recipient-list__header {
        display: none;
    }
    .recipient-item form {
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto;
        gap: 0.5rem 0.6rem;
        padding: 0.5rem 0.75rem;
        align-items: center;
    }
    .recipient-item.recipient-item--has-subgroup form {
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto auto;
        gap: 0.4rem 0.6rem;
    }
    .recipient-item .recipient-phone {
        grid-column: 1;
        grid-row: 1;
        font-size: 0.8rem;
        padding-right: 0.25rem;
    }
    .recipient-item input[type="text"] {
        grid-column: 2;
        grid-row: 1;
        min-width: 0;
    }
    .recipient-item .actions {
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
        padding-top: 0;
    }
    .recipient-item.recipient-item--has-subgroup select {
        grid-column: 1 / -1;
        grid-row: 2;
    }
}
