/* ==========================================================
   TheFinKosha SaaS UI System
   ========================================================== */

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--background);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

/* ==========================================================
   Layout & Wrapper
========================================================== */

.app-layout {
    display: flex;
    min-height: 100vh;
}

.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
}

/* ==========================================================
   Topbar Navigation Layout
========================================================== */

.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-left {
    display: flex;
    align-items: center;
    flex: 1;
}

.topbar-center {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    flex: 1;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    width: 360px;
}

.search-box i,
.search-box svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    border: none;
    background: transparent;
    width: 100%;
    outline: none;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--text);
}

.icon-btn {
    border: none;
    background: transparent;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
}

.icon-btn i,
.icon-btn svg {
    width: 18px;
    height: 18px;
}

.icon-btn:hover {
    background: var(--background);
    color: var(--text);
}

.profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--text-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-bold);
    font-size: var(--text-sm);
    flex-shrink: 0;
}

.profile-info {
    display: flex;
    flex-direction: column;
}

.profile-name {
    font-size: var(--text-sm);
    font-weight: var(--fw-semibold);
    color: var(--text);
    line-height: 1.2;
}

.profile-role {
    font-size: 11px;
    color: var(--text-muted);
}

/* ==========================================================
   Sidebar: Collapsed Icon Rail (Not Hovered) -> Full Expand (Hovered)
========================================================== */

/* Main content wrapper remains fixed at 72px so the page layout never jumps */
.main-wrapper {
    margin-left: 72px !important;
}

/* Sidebar default state (When NOT Hovered) */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 72px; /* Collapsed icon-only width */
    height: 100vh;
    background: var(--sidebar-bg, #FFFFFF);
    border-right: 1px solid var(--border, #E5E7EB);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow-x: hidden;
    overflow-y: auto;
    z-index: 100;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease;
    white-space: nowrap;
}

/* Sidebar hover state (When HOVERED) */
.sidebar:hover {
    width: 270px; /* Full expanded width */
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
}

/* --------------------------------------------------
   Hide all text elements when NOT hovering
-------------------------------------------------- */

/* Logo Text */
.sidebar .logo-text {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sidebar:hover .logo-text {
    opacity: 1;
    visibility: visible;
}

/* Section Headings (GENERAL, SALES, etc.) */
.sidebar .nav-heading {
    opacity: 0;
    visibility: hidden;
    height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease, height 0.2s ease;
}

.sidebar:hover .nav-heading {
    opacity: 1;
    visibility: visible;
    height: auto;
    margin-bottom: 8px;
    padding: 0 12px;
}

/* Navigation Link Labels */
.sidebar .nav-item span {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sidebar:hover .nav-item span {
    opacity: 1;
    visibility: visible;
}

/* Footer Organization Details */
.sidebar .org-details {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sidebar:hover .org-details {
    opacity: 1;
    visibility: visible;
}

/* Logout Button Text */
.sidebar .logout-btn span {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sidebar:hover .logout-btn span {
    opacity: 1;
    visibility: visible;
}

/* --------------------------------------------------
   Layout & Sizing Rules
-------------------------------------------------- */

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 14px;
    border-bottom: 1px solid var(--border, #E5E7EB);
    min-height: var(--topbar-height, 72px);
    box-sizing: border-box;
}

.logo-icon {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: var(--radius-md, 10px);
    background: var(--primary, #2563EB);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-nav {
    padding: 16px 10px;
    flex: 1;
}

.nav-section {
    margin-bottom: 16px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    text-decoration: none;
    color: var(--text-light, #475569);
    padding: 10px 12px;
    border-radius: var(--radius-md, 10px);
    margin-bottom: 4px;
    transition: background 0.15s ease, color 0.15s ease;
    font-weight: 500;
    font-size: 14px;
    height: 42px;
    box-sizing: border-box;
}

.nav-item:hover {
    background: var(--surface-hover, #F8FAFC);
    color: var(--primary, #2563EB);
}

.nav-item.active {
    background: #EFF6FF;
    color: var(--primary, #2563EB);
    font-weight: 600;
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-icon svg,
.nav-icon i {
    width: 18px;
    height: 18px;
}

.sidebar-footer {
    padding: 14px 10px;
    border-top: 1px solid var(--border, #E5E7EB);
    background: var(--sidebar-bg, #FFFFFF);
}

.organization-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding: 0 4px;
}

.org-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: var(--primary, #2563EB);
    color: #FFFFFF;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: var(--radius-md, 10px);
    color: var(--danger, #DC2626);
    transition: background 0.15s ease;
    height: 40px;
    box-sizing: border-box;
}

.logout-btn:hover {
    background: #FEF2F2;
}

/* ==========================================================
   Topbar Header
========================================================== */

.topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    width: 360px;
}

.search-box input {
    border: none;
    background: none;
    width: 100%;
    outline: none;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--text);
}

.icon-btn {
    border: none;
    background: var(--surface);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
}

.icon-btn:hover {
    background: #F1F5F9;
    color: var(--text);
}

.profile {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: 20px;
}

.profile-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary);
    color: var(--text-white);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-bold);
}

.profile-name {
    font-weight: var(--fw-semibold);
}

.profile-role {
    font-size: 13px;
    color: var(--text-muted);
}

/* ==========================================================
   Page Structure & Header
========================================================== */

.page {
    padding: var(--space-8);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-8);
}

.page-title {
    font-size: var(--text-2xl);
    font-weight: var(--fw-bold);
    color: var(--text);
}

.page-subtitle {
    color: var(--text-muted);
    margin-top: 6px;
    font-size: var(--text-sm);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ==========================================================
   Buttons System
========================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-md);
    padding: 10px 18px;
    cursor: pointer;
    text-decoration: none;
    font-family: var(--font-family);
    font-weight: var(--fw-semibold);
    font-size: var(--text-sm);
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: var(--text-white);
}

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

.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--background);
}

.btn-danger {
    background: var(--danger);
    color: var(--text-white);
}

.btn-danger:hover {
    filter: brightness(0.95);
}

/* ==========================================================
   Alerts & Notifications
========================================================== */

.alert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-5);
    border: 1px solid transparent;
    font-size: var(--text-sm);
}

.alert.success {
    background: #ECFDF5;
    border-color: #BBF7D0;
    color: #166534;
}

.alert.error {
    background: #FEF2F2;
    border-color: #FECACA;
    color: #991B1B;
}

.alert.warning {
    background: #FFFBEB;
    border-color: #FDE68A;
    color: #92400E;
}

/* ==========================================================
   KPI Cards & Dashboard Grid
========================================================== */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 16px;
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon.blue { background: #EFF6FF; color: var(--primary); }
.kpi-icon.green { background: #F0FDF4; color: var(--success); }
.kpi-icon.orange { background: #FEF3C7; color: var(--warning); }
.kpi-icon.red { background: #FEF2F2; color: var(--danger); }

.kpi-label {
    font-size: 13px;
    font-weight: var(--fw-medium);
    color: var(--text-light);
    display: block;
    margin-bottom: 4px;
}

.kpi-content h2 {
    font-size: var(--text-2xl);
    font-weight: var(--fw-bold);
    color: var(--text);
    margin: 0;
}

/* ==========================================================
   Standard SaaS Cards & Forms
========================================================== */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: var(--space-6);
    align-items: start;
}

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

.form-container {
    max-width: 840px;
    margin: 0 auto;
}

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-6);
}

.form-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-light);
}

.form-card-title {
    font-size: 15px;
    font-weight: var(--fw-semibold);
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-card-title i {
    width: 18px;
    height: 18px;
    color: var(--primary);
}

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

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

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

.form-label .required {
    color: var(--danger);
}

.form-control {
    width: 100%;
    height: 40px;
    padding: 8px 12px;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    color: var(--text);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* ==========================================================
   Table Components
========================================================== */

.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.table-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-header h3 {
    font-size: var(--text-md);
    font-weight: var(--fw-semibold);
    color: var(--text);
    margin: 0;
}

.table-header p {
    font-size: 13px;
    color: var(--text-muted);
    margin: 2px 0 0 0;
}

.table-responsive {
    overflow-x: auto;
}

.app-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: var(--text-sm);
}

.app-table th {
    background: var(--background);
    padding: 12px 16px;
    font-size: 12px;
    font-weight: var(--fw-semibold);
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
}

.app-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
    vertical-align: middle;
}

.app-table tr:hover {
    background-color: var(--surface-hover);
}

.table-footer {
    padding: 12px 20px;
    background: var(--background);
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ==========================================================
   Auth Layout (Login / Register)
========================================================== */

.auth-body {
    font-family: var(--font-family);
    background-color: var(--background);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-6);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
}

.auth-card.wide {
    max-width: 680px;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: var(--space-6);
}

.brand-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: var(--text-white);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-bold);
}

.brand-text {
    font-size: var(--text-lg);
    font-weight: var(--fw-bold);
    color: var(--text);
}

.auth-header {
    margin-bottom: var(--space-6);
}

.auth-title {
    font-size: var(--text-xl);
    font-weight: var(--fw-bold);
    color: var(--text);
    margin-bottom: 4px;
}

.auth-subtitle {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* ==========================================================
   Dropdown Action System
========================================================== */

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: #FFFFFF;
    border: 1px solid var(--border, #E5E7EB);
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    min-width: 150px;
    padding: 6px;
    z-index: 1000;
    box-sizing: border-box;
}

.dropdown-menu.show {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dropdown-menu a,
.dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text, #0F172A);
    text-decoration: none;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, color 0.15s ease;
    box-sizing: border-box;
    font-family: inherit;
}

.dropdown-menu a:hover,
.dropdown-menu button:hover {
    background-color: var(--background, #F8FAFC);
    color: var(--primary, #2563EB);
}

.dropdown-menu button.danger-btn,
.dropdown-menu .danger-btn {
    color: var(--danger, #DC2626) !important;
    background: transparent;
}

.dropdown-menu button.danger-btn:hover,
.dropdown-menu .danger-btn:hover {
    background-color: #FEF2F2 !important;
    color: #DC2626 !important;
}

.dropdown-menu svg,
.dropdown-menu i {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Ensure table container does not clip floating dropdown menus */
.table-card {
    overflow: visible !important;
}

.table-responsive {
    overflow-x: auto;
    overflow-y: visible;
}

/* ==========================================================
   Global Modal & Loader Utilities
========================================================== */

/* Global Confirmation Modal Backdrop */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-content {
    background: #FFFFFF;
    padding: 24px;
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.modal-content h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text, #0F172A);
}

.modal-content p {
    margin: 0 0 20px 0;
    font-size: 14px;
    color: var(--text-light, #475569);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Global Loader Backdrop */
.global-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loader-card {
    background: #FFFFFF;
    padding: 20px 28px;
    border-radius: var(--radius-md, 8px);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.loader-card p {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text, #0F172A);
}

/* Spinner Animation */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border, #E5E7EB);
    border-top-color: var(--primary, #2563EB);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Utility class to hide elements - MUST be at the very bottom */
.hidden,
.modal.hidden,
.global-loader.hidden {
    display: none !important;
}