/* ============================================================
   Rental Management Platform — Main Stylesheet
   ============================================================ */

:root {
  --primary:       #1a56db;
  --primary-dark:  #1245b8;
  --primary-light: #ebf0ff;
  --secondary:     #6b7280;
  --success:       #057a55;
  --success-bg:    #def7ec;
  --warning:       #9f580a;
  --warning-bg:    #fdf3c7;
  --danger:        #c81e1e;
  --danger-bg:     #fde8e8;
  --info:          #1e429f;
  --info-bg:       #e1effe;
  --bg:            #f9fafb;
  --bg-card:       #ffffff;
  --border:        #e5e7eb;
  --text:          #111827;
  --text-muted:    #6b7280;
  --text-light:    #9ca3af;
  --sidebar-w:     260px;
  --header-h:      64px;
  --radius:        8px;
  --shadow:        0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg:     0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);
  --font:          'Inter', 'Segoe UI', sans-serif;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
ul, ol { list-style: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Auth Layout ────────────────────────────────────────────── */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1a56db 0%, #0e3a8a 100%); padding: 1rem; }
.auth-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); padding: 2.5rem; width: 100%; max-width: 440px; }
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo img { height: 52px; }
.auth-logo h1 { font-size: 1.4rem; font-weight: 700; color: var(--primary); margin-top: .5rem; }
.auth-title { font-size: 1.4rem; font-weight: 700; text-align: center; color: var(--text); margin-bottom: .5rem; }
.auth-subtitle { text-align: center; color: var(--text-muted); margin-bottom: 1.75rem; font-size: .9rem; }
.auth-footer { text-align: center; margin-top: 1.5rem; font-size: .875rem; color: var(--text-muted); }

/* ── App Layout ─────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: #111827; color: #e5e7eb; position: fixed; top: 0; left: 0; height: 100vh; display: flex; flex-direction: column; z-index: 100; transition: transform .3s ease; }
.sidebar-logo { padding: 1.25rem 1.5rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-logo h2 { font-size: 1.05rem; font-weight: 700; color: #fff; line-height: 1.3; }
.sidebar-logo span { font-size: .75rem; color: #9ca3af; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem 0; }
.sidebar-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; padding: .5rem 1.5rem .25rem; }
.sidebar-nav a { display: flex; align-items: center; gap: .75rem; padding: .625rem 1.5rem; color: #9ca3af; font-size: .875rem; transition: all .15s; border-left: 3px solid transparent; }
.sidebar-nav a:hover, .sidebar-nav a.active { color: #fff; background: rgba(255,255,255,.06); border-left-color: var(--primary); text-decoration: none; }
.sidebar-nav a i { width: 18px; text-align: center; font-size: 1rem; }
.sidebar-nav .badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px; font-size: .68rem; padding: .1rem .45rem; }
.sidebar-footer { padding: 1rem 1.5rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user { display: flex; align-items: center; gap: .75rem; }
.sidebar-user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .875rem; }
.sidebar-user-info small { display: block; color: #9ca3af; font-size: .72rem; }

.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: var(--header-h); background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 1.75rem; gap: 1rem; position: sticky; top: 0; z-index: 50; }
.topbar-title { font-weight: 600; font-size: 1.05rem; color: var(--text); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.page-body { flex: 1; padding: 1.75rem; }

/* ── Components ─────────────────────────────────────────────── */
/* Cards */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: .95rem; font-weight: 600; }
.card-body { padding: 1.25rem; }
.card-footer { padding: .875rem 1.25rem; border-top: 1px solid var(--border); background: #f9fafb; border-radius: 0 0 var(--radius) var(--radius); }

/* Stat Cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; display: flex; align-items: flex-start; gap: 1rem; box-shadow: var(--shadow); }
.stat-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.stat-icon.blue   { background: #dbeafe; color: #1d4ed8; }
.stat-icon.green  { background: var(--success-bg); color: var(--success); }
.stat-icon.red    { background: var(--danger-bg); color: var(--danger); }
.stat-icon.orange { background: #fff7ed; color: #c2410c; }
.stat-icon.purple { background: #f5f3ff; color: #7c3aed; }
.stat-icon.yellow { background: var(--warning-bg); color: var(--warning); }
.stat-info label { font-size: .78rem; color: var(--text-muted); display: block; margin-bottom: .2rem; }
.stat-info .value { font-size: 1.4rem; font-weight: 700; line-height: 1.2; }
.stat-info .sub { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .45rem; padding: .55rem 1.1rem; border-radius: var(--radius); font-weight: 500; font-size: .875rem; border: 1px solid transparent; cursor: pointer; transition: all .15s; line-height: 1.4; white-space: nowrap; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #f3f4f6; }
.btn-success   { background: var(--success); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-warning   { background: #d97706; color: #fff; }
.btn-outline-primary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary-light); }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { padding: .5rem; border-radius: 6px; }

/* Forms */
.form-group { margin-bottom: 1.1rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
label { display: block; font-size: .85rem; font-weight: 500; color: var(--text); margin-bottom: .35rem; }
label .required { color: var(--danger); margin-left: .2rem; }
.form-control { width: 100%; padding: .6rem .85rem; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); transition: border .15s, box-shadow .15s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }
.form-control.is-invalid { border-color: var(--danger); }
.form-error { font-size: .78rem; color: var(--danger); margin-top: .3rem; }
.form-hint  { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .75rem center; padding-right: 2.5rem; }
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius) 0 0 var(--radius); }
.input-group .input-suffix { padding: .6rem .85rem; background: #f3f4f6; border: 1px solid var(--border); border-left: none; border-radius: 0 var(--radius) var(--radius) 0; color: var(--text-muted); font-size: .875rem; white-space: nowrap; display: flex; align-items: center; }

/* Tables */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { background: #f9fafb; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); font-weight: 600; padding: .75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: .875rem 1rem; border-bottom: 1px solid var(--border); font-size: .875rem; vertical-align: middle; }
tbody tr:hover { background: #fafafa; }
tbody tr:last-child td { border-bottom: none; }

/* Badges / Status */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 500; }
.badge-green   { background: var(--success-bg); color: var(--success); }
.badge-red     { background: var(--danger-bg); color: var(--danger); }
.badge-yellow  { background: var(--warning-bg); color: var(--warning); }
.badge-blue    { background: var(--info-bg); color: var(--info); }
.badge-gray    { background: #f3f4f6; color: var(--secondary); }
.badge-purple  { background: #f5f3ff; color: #6d28d9; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Alerts */
.alert { border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1rem; font-size: .875rem; display: flex; align-items: flex-start; gap: .75rem; }
.alert i { margin-top: .1rem; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #a7f3d0; }
.alert-danger  { background: var(--danger-bg); color: var(--danger); border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fcd34d; }
.alert-info    { background: var(--info-bg); color: var(--info); border: 1px solid #93c5fd; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal-backdrop.show { opacity: 1; pointer-events: all; }
.modal { background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; transform: translateY(20px); transition: transform .2s; }
.modal-backdrop.show .modal { transform: translateY(0); }
.modal.modal-lg { max-width: 780px; }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.25rem; color: var(--text-muted); line-height: 1; padding: .2rem; }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .75rem; }

/* Toast */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 999; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: .85rem 1.1rem; min-width: 280px; max-width: 360px; display: flex; align-items: center; gap: .75rem; font-size: .875rem; animation: slideInRight .2s ease; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid #f59e0b; }
.toast.info    { border-left: 4px solid var(--primary); }
@keyframes slideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* Pagination */
.pagination { display: flex; align-items: center; gap: .35rem; margin-top: 1rem; }
.pagination button { padding: .4rem .75rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; font-size: .8rem; cursor: pointer; color: var(--text); transition: all .15s; }
.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: .5; cursor: not-allowed; }
.pagination-info { font-size: .8rem; color: var(--text-muted); margin-left: auto; }

/* Misc */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: .75rem; }
.page-header h2 { font-size: 1.25rem; font-weight: 700; }
.page-header p  { font-size: .875rem; color: var(--text-muted); margin-top: .2rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--text-muted); }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: .4; }
.empty-state p { font-size: .875rem; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-5 { margin-bottom: 1.25rem; }
.mb-6 { margin-bottom: 1.5rem; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fs-sm { font-size: .8rem; }
.fs-xs { font-size: .72rem; }

/* Chat */
.chat-wrapper { display: flex; flex-direction: column; height: calc(100vh - var(--header-h) - 3.5rem); max-height: 640px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .75rem; background: #f9fafb; border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.chat-msg { display: flex; gap: .6rem; max-width: 70%; }
.chat-msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-bubble { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: .6rem .9rem; font-size: .875rem; }
.chat-bubble .ts { font-size: .68rem; color: var(--text-light); margin-top: .3rem; }
.chat-msg.mine .chat-bubble { background: var(--primary); color: #fff; border-color: var(--primary); }
.chat-msg.mine .chat-bubble .ts { color: rgba(255,255,255,.7); }
.chat-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 600; flex-shrink: 0; align-self: flex-end; }
.chat-input-row { display: flex; gap: .5rem; border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); padding: .75rem; background: #fff; }
.chat-input-row .form-control { border-radius: 99px; }

/* Tabs */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.25rem; gap: .25rem; }
.tab-btn { padding: .6rem 1.1rem; font-size: .875rem; font-weight: 500; border: none; background: none; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Loading */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.spinner.dark { border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,.75); z-index: 999; display: flex; align-items: center; justify-content: center; }

/* Status pills helper */
.status-active      { color: var(--success); }
.status-expired, .status-terminated, .status-overdue { color: var(--danger); }
.status-draft, .status-pending { color: var(--warning); }
.status-renewed     { color: var(--info); }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .page-body { padding: 1rem; }
  .modal { max-width: 100%; margin: 0; border-radius: 12px 12px 0 0; position: fixed; bottom: 0; }
}
