/* css/main.css — Global styles, CSS variables, layout */
/* DETASAD Sales Engine */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── CSS CUSTOM PROPERTIES ─── */
:root {
    --color-primary: #005B7F;
    --color-primary-dark: #004a68;
    --color-primary-darker: #003d55;
    --color-cyan: #6FCCDD;
    --color-lime: #C5D82D;
    --color-grey: #4A4A4A;
    --color-danger: #EF4444;
    --color-warning: #F59E0B;
    --color-bg: #F8FAFC;
    --color-surface: #FFFFFF;
    --color-border: #E2E8F0;
    --color-text-muted: #6B7280;
    --sidebar-width: 240px;
    --mobile-nav-height: 64px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 91, 127, 0.12);
    --shadow-lg: 0 8px 24px rgba(0, 91, 127, 0.16);
    --transition: 0.2s ease;
}

/* ─── RESET ─── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 14px;
    color: var(--color-grey);
    background: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--color-cyan);
}

img {
    max-width: 100%;
    display: block;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: 14px;
}

ul,
ol {
    list-style: none;
}

/* ─── LAYOUT ─── */
.sidebar {
    display: none;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--color-primary) 0%, var(--color-primary-darker) 100%);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    flex-direction: column;
    padding: 24px 0;
    z-index: 100;
    overflow-x: hidden;
    overflow-y: auto;
}

.main-content {
    min-height: 100vh;
    padding: 24px;
    padding-bottom: calc(var(--mobile-nav-height) + 24px);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    z-index: 100;
    align-items: stretch;
}

@media (min-width: 768px) {
    .sidebar {
        display: flex;
    }

    .main-content {
        margin-left: var(--sidebar-width);
        padding: 32px;
        padding-bottom: 32px;
    }

    .mobile-nav {
        display: none;
    }
}

/* ─── TYPOGRAPHY ─── */
.page-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--color-grey);
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-grey);
}

.text-muted {
    color: var(--color-text-muted);
}

.text-sm {
    font-size: 12px;
}

.text-danger {
    color: var(--color-danger);
}

.text-overdue {
    color: var(--color-danger);
    font-weight: 600;
}

.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── BUTTONS ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn:active {
    transform: translateY(1px);
}

.btn i {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-dark);
}

.btn-cyan {
    background: var(--color-cyan);
    color: var(--color-primary-darker);
}

.btn-cyan:hover {
    background: #5ab8ca;
}

.btn-secondary,
.btn-ghost {
    background: transparent;
    color: var(--color-primary);
    border: 1.5px solid var(--color-primary);
}

.btn-secondary:hover,
.btn-ghost:hover {
    background: rgba(0, 91, 127, 0.06);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 12px;
    border-radius: var(--radius-sm);
}

.btn-icon {
    padding: 8px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--color-bg);
    color: var(--color-primary);
    border-color: var(--color-cyan);
}

/* ─── CARDS ─── */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    padding: 24px;
}

.card-hover {
    transition: box-shadow var(--transition), transform var(--transition);
}

.card-hover:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-border);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
}

/* ─── BADGES ─── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-development {
    background: #F3F4F6;
    color: #6B7280;
}

.badge-submitted {
    background: #E0F0F8;
    color: #005B7F;
}

.badge-negotiation {
    background: #FEF3C7;
    color: #92400E;
}

.badge-won,
.badge-closed_won {
    background: #ECFFD8;
    color: #4B6800;
}

.badge-lost,
.badge-closed_lost {
    background: #FEE2E2;
    color: #991B1B;
}

.badge-renewal_failed {
    background: #FEE2E2;
    color: #991B1B;
}

.badge-cancelled {
    background: #F3F4F6;
    color: #374151;
}

.badge-low {
    background: #F3F4F6;
    color: #6B7280;
}

.badge-medium {
    background: #FEF3C7;
    color: #92400E;
}

.badge-high {
    background: #FEE2E2;
    color: #991B1B;
}

.badge-critical {
    background: #EDE9FE;
    color: #5B21B6;
}

/* ─── DATA TABLE ─── */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    background: var(--color-bg);
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-grey);
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr {
    transition: background var(--transition);
}

.data-table tbody tr:hover {
    background: rgba(0, 91, 127, 0.03);
}

.row-overdue {
    background: rgba(239, 68, 68, 0.03) !important;
}

/* ─── FORMS ─── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
}

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-grey);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--color-grey);
    background: var(--color-surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--color-cyan);
    box-shadow: 0 0 0 3px rgba(111, 204, 221, 0.15);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: #B0BAC4;
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

.form-hint {
    font-size: 12px;
    color: var(--color-text-muted);
}

.form-error {
    font-size: 12px;
    color: var(--color-danger);
}

.form-row {
    display: grid;
    gap: 16px;
}

@media (min-width: 640px) {
    .form-row-2 {
        grid-template-columns: 1fr 1fr;
    }

    .form-row-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ─── MODAL ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    transform: translateY(32px);
    transition: transform var(--transition);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

@media (min-width: 768px) {
    .modal-overlay {
        align-items: center;
        padding: 24px;
    }

    .modal {
        border-radius: var(--radius-xl);
        max-width: 560px;
        max-height: 85vh;
        transform: scale(0.96);
    }

    .modal-overlay.active .modal {
        transform: scale(1);
    }

    .modal-lg {
        max-width: 720px;
    }

    .modal-xl {
        max-width: 900px;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

.modal-close:hover {
    background: var(--color-bg);
    color: var(--color-danger);
}

.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
}

/* ─── EMPTY STATE ─── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
    color: var(--color-text-muted);
}

.empty-state i {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    color: var(--color-border);
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-grey);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 14px;
    max-width: 320px;
}

.empty-state .btn {
    margin-top: 16px;
}

/* ─── SPINNER ─── */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 48px;
    color: var(--color-text-muted);
}

.loading-text {
    font-size: 12px;
    color: var(--color-text-muted);
}

/* ─── TOAST ─── */
#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    max-width: 360px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--color-border);
    pointer-events: all;
    opacity: 0;
    transform: translateX(24px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.toast-visible {
    opacity: 1;
    transform: translateX(0);
}

.toast-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-grey);
}

.toast-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px;
    display: flex;
}

.toast-close i {
    width: 14px;
    height: 14px;
}

.toast-success {
    border-left-color: var(--color-lime);
}

.toast-success .toast-icon {
    color: var(--color-lime);
}

.toast-error {
    border-left-color: var(--color-danger);
}

.toast-error .toast-icon {
    color: var(--color-danger);
}

.toast-info {
    border-left-color: var(--color-cyan);
}

.toast-info .toast-icon {
    color: var(--color-cyan);
}

.toast-warning {
    border-left-color: var(--color-warning);
}

.toast-warning .toast-icon {
    color: var(--color-warning);
}

/* ─── UTILITIES ─── */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-end {
    justify-content: flex-end;
}

.gap-sm {
    gap: 8px;
}

.gap-md {
    gap: 16px;
}

.gap-lg {
    gap: 24px;
}

.mt-md {
    margin-top: 16px;
}

.mt-lg {
    margin-top: 24px;
}

.mb-md {
    margin-bottom: 16px;
}

.mb-lg {
    margin-bottom: 24px;
}

.w-full {
    width: 100%;
}

.divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 16px 0;
}