:root {
    --bg: #f4f7fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --border: #e5e7eb;
    --table-header: #1e3a8a;
    --danger: #dc2626;
    --warning: #d97706;
    --success: #16a34a;
    --shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

body.dark {
    --bg: #0f172a;
    --card: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --border: #374151;
    --table-header: #172554;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.25s ease, color 0.25s ease;
}

.readonly-input {
    opacity: 0.85;
    cursor: not-allowed;
    background: rgba(148, 163, 184, 0.12) !important;
}

/* FINAL FIX - TS Members Action Column */
.members-table {
    width: 100%;
    table-layout: fixed !important;
}

.members-table th:nth-child(1),
.members-table td:nth-child(1) {
    width: 24%;
}

.members-table th:nth-child(2),
.members-table td:nth-child(2) {
    width: 20%;
}

.members-table th:nth-child(3),
.members-table td:nth-child(3) {
    width: 30%;
}

.members-table th:nth-child(4),
.members-table td:nth-child(4) {
    width: 14%;
}

.members-table th:nth-child(5),
.members-table td:nth-child(5) {
    width: 12% !important;
    text-align: center !important;
    vertical-align: middle !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
}

.members-table td:nth-child(5) {
    position: relative;
}

.members-table td:nth-child(5) form {
    margin: 0 auto !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    width: fit-content !important;
    display: block !important;
}

.members-table .member-remove-btn {
    display: inline-block !important;
    height: 34px !important;
    min-width: 82px !important;
    padding: 0 14px !important;
    border-radius: 8px !important;
    background: var(--danger) !important;
    color: white !important;
    border: none !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    line-height: 34px !important;
    text-align: center !important;
    cursor: pointer !important;
}

.member-remove-btn:hover {
    background: #b91c1c;
}

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 18px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.filter-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
}

.attachments-main-btn {
    text-decoration: none;
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    color: white;
    border: 1px solid transparent;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
    transition: 0.2s;
    white-space: nowrap;
}

.attachments-main-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.35);
}

.sort-field select {
    min-width: 190px;
}

.brand h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
}

.brand p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--muted);
}

.switch {
    position: relative;
    width: 48px;
    height: 25px;
}

.switch input {
    display: none;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cbd5e1;
    border-radius: 999px;
    transition: 0.25s;
}

.slider:before {
    content: "";
    position: absolute;
    height: 19px;
    width: 19px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.25s;
}

.required-star {
    color: var(--danger);
    font-weight: 800;
    margin-left: 3px;
}

input:checked + .slider {
    background: var(--primary);
}

input:checked + .slider:before {
    transform: translateX(23px);
}

.container {
    padding: 28px 30px;
}

.section-subtitle {
    color: var(--muted);
    margin-top: -10px;
    margin-bottom: 20px;
    font-size: 14px;
}

.card-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 18px;
    margin-bottom: 30px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.card h3 {
    margin: 0;
    font-size: 14px;
    color: var(--muted);
    font-weight: 600;
}

.card p {
    font-size: 34px;
    margin: 10px 0 0;
    font-weight: 800;
    color: var(--primary);
}

.table-wrapper {
    overflow-x: auto;
    background: var(--card);
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

th, td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 14px;
}

th {
    background: var(--table-header);
    color: white;
    font-weight: 600;
}

tr:hover td {
    background: rgba(37, 99, 235, 0.06);
}

.critical {
    color: var(--danger);
    font-weight: 700;
}

.warning {
    color: var(--warning);
    font-weight: 700;
}

.btn-small {
    padding: 7px 11px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    display: inline-block;
}

.btn-small:hover {
    background: var(--primary-dark);
}

form {
    background: var(--card);
    padding: 26px;
    border-radius: 18px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    max-width: 1100px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 18px 22px;
}

.form-full {
    grid-column: 1 / -1;
}

label {
    display: block;
    margin-bottom: 7px;
    font-weight: 600;
    font-size: 14px;
}

.help-text {
    font-size: 12px;
    color: var(--muted);
    margin-top: 5px;
}

input, select, textarea {
    width: 100%;
    padding: 11px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
}

textarea {
    min-height: 90px;
    resize: vertical;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

button {
    margin-top: 24px;
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 22px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
}

button:hover {
    background: var(--primary-dark);
}

.form-header {
    margin-bottom: 22px;
}

.form-header h2 {
    margin-bottom: 6px;
}

.form-header p {
    color: var(--muted);
    margin: 0;
    font-size: 14px;
}

@media (max-width: 800px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        align-items: flex-start;
        gap: 15px;
        flex-direction: column;
    }
}

select:invalid {
    color: var(--muted);
}

select option {
    color: var(--text);
}

.btn-delete {
    padding: 7px 11px;
    background: var(--danger);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    display: inline-block;
    margin-left: 6px;
    border: none;
    cursor: pointer;
}

.btn-delete:hover {
    background: #b91c1c;
}

.action-buttons {
    display: flex;
    gap: 6px;
    align-items: center;
}

.action-select {
    width: 120px;
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
}

.action-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.login-wrapper {
    min-height: 65vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-actions {
    display: flex;
    justify-content: center;
    align-items: center;
}

.login-main-btn,
.microsoft-login-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-width: 180px;
    height: 42px;
    padding: 0 18px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
    text-decoration: none;
    border: none;
    cursor: pointer;
    background: var(--primary);
    color: white;
    box-sizing: border-box;
    transition: 0.2s;
}

.login-main-btn:hover,
.microsoft-login-btn:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}

.microsoft-login-btn {
    border: none;
}

.login-card {
    max-width: 430px;
    width: 100%;
}

.login-card h2 {
    margin-bottom: 8px;
}

.login-card p {
    color: var(--muted);
    margin-bottom: 20px;
}

.login-error {
    background: rgba(220, 38, 38, 0.12);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.25);
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 14px;
    font-size: 14px;
}

.nav-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    margin-bottom: 28px;
    width: 100%;
}

.nav-left {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
}

.nav-left .nav-link {
    text-decoration: none;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
    transition: 0.2s;
}

.nav-left .nav-link:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-1px);
}

.nav-left .nav-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
}

.nav-left .nav-add {
    background: linear-gradient(135deg, #16a34a, #22c55e);
    color: white;
    border-color: transparent;
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(34, 197, 94, 0.20);
}

.nav-left .nav-add:hover,
.nav-left .nav-add.active {
    background: linear-gradient(135deg, #15803d, #16a34a);
    color: white;
    border-color: transparent;
    box-shadow: 0 10px 22px rgba(34, 197, 94, 0.32);
}

.nav-right a {
    text-decoration: none;
    background: linear-gradient(135deg, #7c3aed, #2563eb);
    color: white;
    border: 1px solid transparent;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.25);
    transition: 0.2s;
    white-space: nowrap;
}

.nav-right a:hover,
.nav-right a.active {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.38);
    outline: 2px solid rgba(255, 255, 255, 0.22);
}

.nav-right a:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.35);
}

.filter-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}

.filter-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

.filter-field label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.filter-field input,
.filter-field select {
    width: 100%;
    padding: 10px 11px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.filter-actions {
    display: flex;
    gap: 8px;
    align-items: end;
}

.filter-btn,
.reset-btn {
    height: 42px;
    min-width: 78px;
    padding: 0 14px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
    line-height: 42px;
    text-align: center;
    box-sizing: border-box;
    cursor: pointer;
}

.filter-btn {
    background: var(--primary);
    color: white;
    border: 1px solid var(--primary);
}

.reset-btn {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    text-decoration: none;
    display: inline-block;
}

.reset-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

@media (max-width: 1100px) {
    .filter-grid {
        grid-template-columns: 1fr 1fr;
    }

    .filter-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 700px) {
    .filter-grid {
        grid-template-columns: 1fr;
    }
}

.user-settings-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.user-settings-btn {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.user-settings-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.user-settings-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 48px;
    min-width: 260px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 14px;
    z-index: 999;
}

.user-settings-menu.show {
    display: block;
}

.user-menu-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 12px;
}

.user-menu-header strong {
    display: block;
    font-size: 14px;
    color: var(--text);
}

.user-menu-header span {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}

.user-menu-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 10px 0;
    color: var(--text);
    font-size: 14px;
}

.logout-menu-link {
    display: block;
    margin-top: 10px;
    text-align: center;
    text-decoration: none;
    background: var(--danger);
    color: white;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 700;
}

.logout-menu-link:hover {
    background: #b91c1c;
}

.user-menu-link {
    display: block;
    margin-top: 10px;
    text-align: center;
    text-decoration: none;
    background: var(--primary);
    color: white;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 700;
}

.user-menu-link:hover {
    background: var(--primary-dark);
}

.user-menu-link.danger-link {
    background: #7c2d12;
}

.user-menu-link.danger-link:hover {
    background: #9a3412;
}

.dashboard-layout {
    display: grid;
    grid-template-columns: 1.3fr 0.7fr;
    gap: 20px;
    align-items: stretch;
    margin-bottom: 28px;
}

.pie-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.pie-chart {
    width: 190px;
    height: 190px;
    border-radius: 50%;
    margin: 12px auto 18px;
    background: conic-gradient(
        #22c55e 0deg var(--active-deg),
        #f59e0b var(--active-deg) var(--expiring-deg),
        #ef4444 var(--expiring-deg) var(--expired-deg),
        #3b82f6 var(--expired-deg) 360deg
    );
}

.pie-legend {
    display: grid;
    gap: 8px;
    font-size: 13px;
}

.legend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

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

.legend-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
}

.dot-active { background: #22c55e; }
.dot-expiring { background: #f59e0b; }
.dot-expired { background: #ef4444; }
.dot-other { background: #3b82f6; }

@media (max-width: 1000px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
    }
}

/* FINAL FULL-WIDTH TS MEMBERS TABLE */
.members-table-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
}

.members-table {
    width: 100% !important;
    max-width: 100% !important;
    table-layout: fixed !important;
}

.members-table th,
.members-table td {
    padding: 14px 18px !important;
    vertical-align: middle !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.members-table th:nth-child(1),
.members-table td:nth-child(1) {
    width: 24% !important;
}

.members-table th:nth-child(2),
.members-table td:nth-child(2) {
    width: 18% !important;
}

.members-table th:nth-child(3),
.members-table td:nth-child(3) {
    width: 30% !important;
}

.members-table th:nth-child(4),
.members-table td:nth-child(4) {
    width: 15% !important;
    text-align: center !important;
}

.members-table th:nth-child(5),
.members-table td:nth-child(5) {
    width: 13% !important;
    text-align: center !important;
    vertical-align: middle !important;
}

.member-action-td {
    text-align: center !important;
    vertical-align: middle !important;
}

.member-remove-link {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 32px !important;
    min-width: 78px !important;
    padding: 0 12px !important;
    border-radius: 8px !important;
    background: #dc2626 !important;
    color: white !important;
    border: none !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    line-height: 32px !important;
    text-decoration: none !important;
    cursor: pointer !important;
}

.member-remove-link:hover {
    background: #b91c1c !important;
}
