/* Smart Care System Admin Panel - Modern Clean Responsive UI */
:root {
  --bg-dark: #0f172a;
  --card-bg: #1e293b;
  --border-color: #334155;
  --accent-color: #38bdf8;
  --accent-hover: #0284c7;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1.5;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  max-width: 100%;
  min-width: 0;
}

.sidebar {
  width: 250px;
  min-width: 250px;
  background-color: #0b1120;
  border-right: 1px solid var(--border-color);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-color);
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 0.65rem 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav-link:hover, .nav-link.active {
  background-color: var(--card-bg);
  color: var(--text-main);
}

.nav-link.active {
  border-left: 3px solid var(--accent-color);
}

.main-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  gap: 1rem;
  flex-wrap: wrap;
  min-width: 0;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  min-width: 0;
  overflow-wrap: break-word;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.btn-logout {
  color: var(--danger);
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
}

.btn-logout:hover {
  background-color: rgba(239, 68, 68, 0.1);
}

/* Cards & Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
  min-width: 0;
}

.stat-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
  min-width: 0;
}

a.stat-card {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

a.stat-card:hover,
a.stat-card:focus-visible {
  border-color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  outline: none;
}

.stat-title {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 0.5rem;
  color: var(--text-main);
  overflow-wrap: break-word;
}

/* Data Tables & Cards */
.card-table {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 2rem;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
  min-width: 0;
}

.table-title {
  font-size: 1.1rem;
  font-weight: 600;
  min-width: 0;
  overflow-wrap: break-word;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  min-width: 0;
}

th, td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
  min-width: 0;
}

th {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

/* Utilities for wrapping and breaking long values */
.break-code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.break-word {
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: break-word;
}

.cell-value {
  min-width: 0;
  max-width: 100%;
}

.action-btn-group {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* System Audit Log Description */
td.cell-description {
  overflow-wrap: break-word;
  word-break: break-word;
  min-width: 260px;
  max-width: none;
  width: auto;
  line-height: 1.45;
  white-space: normal;
}

/* System Audit Log Table Column Proportions (Desktop & Tablet) */
.audit-table {
  width: 100%;
}

.audit-table th.col-audit-time,
.audit-table td.col-audit-time {
  width: 160px;
  min-width: 140px;
  white-space: nowrap;
}

.audit-table th.col-audit-user,
.audit-table td.col-audit-user {
  width: 120px;
  min-width: 95px;
  white-space: nowrap;
}

.audit-table th.col-audit-action,
.audit-table td.col-audit-action {
  width: 155px;
  min-width: 125px;
  white-space: nowrap;
}

.audit-table th.col-audit-desc,
.audit-table td.col-audit-desc {
  width: auto;
  min-width: 280px;
  max-width: none;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-active, .badge-approved { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-pending { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-converted { background: rgba(56, 189, 248, 0.15); color: var(--accent-color); }
.badge-suspended, .badge-deactivated, .badge-rejected { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-expired, .badge-revoked { background: rgba(148, 163, 184, 0.15); color: var(--text-muted); }

/* Buttons & Forms */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary { background-color: var(--accent-color); color: #0f172a; }
.btn-primary:hover { background-color: var(--accent-hover); }
.btn-danger { background-color: var(--danger); color: #ffffff; }
.btn-secondary { background-color: var(--border-color); color: var(--text-main); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background-color: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-main);
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-color);
}

/* Alert Banners */
.alert {
  padding: 0.85rem 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  font-weight: 500;
  overflow-wrap: break-word;
}
.alert-success { background: rgba(34, 197, 94, 0.15); border: 1px solid var(--success); color: var(--success); }
.alert-danger { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--danger); color: var(--danger); }
.alert-warning { background: rgba(245, 158, 11, 0.15); border: 1px solid var(--warning); color: var(--warning); }

/* Login Page Styling */
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 2.5rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  min-width: 0;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* Tablet / Medium-Width Breakpoint (769px to 1100px) */
@media (min-width: 769px) and (max-width: 1100px) {
  /* Layout & Sidebar */
  .sidebar {
    width: 195px;
    min-width: 195px;
    padding: 1.25rem 0.75rem;
  }

  .brand-title {
    font-size: 1.05rem;
    margin-bottom: 1.25rem;
  }

  .nav-link {
    padding: 0.5rem 0.65rem;
    font-size: 0.82rem;
  }

  .main-content {
    padding: 1.25rem 0.85rem;
  }

  .top-bar {
    margin-bottom: 1.25rem;
    gap: 0.75rem;
  }

  .page-title {
    font-size: 1.3rem;
  }

  .card-table {
    padding: 0.85rem 0.75rem;
    margin-bottom: 1.25rem;
  }

  .table-header {
    margin-bottom: 0.85rem;
    gap: 0.75rem;
  }

  .table-title {
    font-size: 1.05rem;
  }

  /* Tablet Table & Cell Optimization */
  table {
    font-size: 0.82rem;
  }

  th, td {
    padding: 0.45rem 0.4rem;
    font-size: 0.8rem;
  }

  th {
    font-size: 0.72rem;
    white-space: normal;
    line-height: 1.25;
    vertical-align: bottom;
  }

  .badge {
    padding: 0.2rem 0.4rem;
    font-size: 0.68rem;
  }

  code {
    font-size: 0.78em;
    padding: 0.1rem 0.25rem;
  }

  .action-btn-group {
    gap: 0.25rem;
  }

  .action-btn-group .btn,
  td .btn {
    padding: 0.25rem 0.45rem;
    font-size: 0.72rem;
  }

  /* Customer Table Tablet Optimization */
  .customer-table th,
  .customer-table td {
    padding: 0.45rem 0.35rem;
    font-size: 0.78rem;
  }

  .customer-table th {
    font-size: 0.7rem;
    white-space: normal;
    line-height: 1.2;
    vertical-align: bottom;
  }

  .customer-table td[data-label="Owner / Contact"],
  .customer-table td[data-label="Property"],
  .customer-table td[data-label="Mobile / Email"],
  .customer-table td[data-label="Last Seen"] {
    white-space: normal;
    line-height: 1.25;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  .customer-table td[data-label="Mobile / Email"] .cell-value {
    font-size: 0.76rem;
  }

  .customer-table .badge {
    font-size: 0.64rem;
    padding: 0.15rem 0.35rem;
    white-space: nowrap;
  }

  .customer-table code {
    font-size: 0.74rem;
    padding: 0.1rem 0.2rem;
  }

  .customer-table td[data-label="Actions"] .action-btn-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 48px;
  }

  .customer-table td[data-label="Actions"] .btn {
    padding: 0.2rem 0.35rem;
    font-size: 0.7rem;
    text-align: center;
    justify-content: center;
    width: 100%;
  }

  /* License Table Tablet Optimization */
  .license-table th,
  .license-table td {
    padding: 0.45rem 0.4rem;
    font-size: 0.8rem;
  }

  .license-table th {
    font-size: 0.7rem;
    white-space: normal;
    line-height: 1.2;
    vertical-align: bottom;
  }

  .license-table td[data-label="Customer / Business"],
  .license-table td[data-label="Plan"] {
    white-space: normal;
    line-height: 1.25;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  .license-table .badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
  }

  .license-table td[data-label="Actions"] .action-btn-group {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 50px;
  }

  .license-table td[data-label="Actions"] .btn {
    padding: 0.2rem 0.4rem;
    font-size: 0.72rem;
    text-align: center;
    justify-content: center;
    width: 100%;
  }

  /* Authorized Devices Table Tablet Optimization */
  .devices-table th,
  .devices-table td {
    padding: 0.45rem 0.4rem;
    font-size: 0.8rem;
  }

  .devices-table th {
    font-size: 0.7rem;
    white-space: normal;
    line-height: 1.2;
    vertical-align: bottom;
  }

  .devices-table td[data-label="Business / License"],
  .devices-table td[data-label="Device Identity"] {
    white-space: normal;
    line-height: 1.25;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  .devices-table td[data-label="Activated Date"],
  .devices-table td[data-label="Last Verified"] {
    font-size: 0.76rem;
    white-space: normal;
    line-height: 1.25;
  }

  .devices-table .badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
  }

  .devices-table td[data-label="Actions"] .action-btn-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 65px;
  }

  .devices-table td[data-label="Actions"] .btn {
    padding: 0.2rem 0.4rem;
    font-size: 0.72rem;
    text-align: center;
    justify-content: center;
    width: 100%;
  }

  /* System Audit Log Table Tablet Optimization */
  .audit-table th.col-audit-time,
  .audit-table td.col-audit-time {
    width: 135px;
    min-width: 120px;
    font-size: 0.76rem;
  }

  .audit-table th.col-audit-user,
  .audit-table td.col-audit-user {
    width: 105px;
    min-width: 85px;
  }

  .audit-table th.col-audit-action,
  .audit-table td.col-audit-action {
    width: 130px;
    min-width: 110px;
  }

  .audit-table th.col-audit-desc,
  .audit-table td.col-audit-desc {
    width: auto;
    min-width: 220px;
  }

  /* Quick links on Customer & License views */
  .quick-links {
    gap: 0.35rem;
  }

  .quick-links .btn {
    padding: 0.25rem 0.45rem;
    font-size: 0.72rem;
  }
}

/* Mobile Breakpoint (<= 768px) */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
    min-width: 0;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0.85rem;
  }

  .brand-title {
    margin-bottom: 0.85rem;
    font-size: 1.1rem;
  }

  .nav-menu {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .nav-link {
    padding: 0.45rem 0.65rem;
    font-size: 0.8rem;
    border-radius: 4px;
  }

  .nav-link.active {
    border-left: none;
    border-bottom: 2px solid var(--accent-color);
  }

  .main-content {
    padding: 1.25rem 0.85rem;
    min-width: 0;
  }

  .top-bar {
    margin-bottom: 1.25rem;
    gap: 0.75rem;
  }

  .page-title {
    font-size: 1.25rem;
  }

  .user-profile {
    font-size: 0.85rem;
    gap: 0.5rem;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
  }

  .stat-card {
    padding: 0.85rem;
  }

  .stat-title {
    font-size: 0.75rem;
  }

  .stat-value {
    font-size: 1.35rem;
  }

  .card-table {
    padding: 0.85rem;
    margin-bottom: 1.25rem;
  }

  .table-header {
    margin-bottom: 0.85rem;
    gap: 0.75rem;
  }

  .table-title {
    font-size: 1rem;
  }

  /* Responsive Stacked Card-Row Table Transformation */
  .responsive-table {
    display: block;
    width: 100%;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table tbody {
    display: block;
    width: 100%;
  }

  .responsive-table tr {
    display: block;
    width: 100%;
    margin-bottom: 0.85rem;
    padding: 0.85rem;
    background-color: rgba(15, 23, 42, 0.45);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-sizing: border-box;
  }

  .responsive-table tr:hover {
    background-color: rgba(15, 23, 42, 0.65);
  }

  .responsive-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(51, 65, 85, 0.4);
    text-align: right;
    min-width: 0;
    gap: 0.75rem;
    box-sizing: border-box;
  }

  .responsive-table td:last-child {
    border-bottom: none;
    padding-bottom: 0;
    padding-top: 0.65rem;
  }

  .responsive-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
    flex-shrink: 0;
    max-width: 42%;
    margin-top: 0.1rem;
  }

  .responsive-table td .cell-value,
  .responsive-table td > :not(::before) {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* Description and stacked cells: full-width block below label */
  .responsive-table td.cell-description,
  .responsive-table td.cell-stacked,
  .responsive-table td[data-label="Description"],
  .responsive-table td[data-label="Address"] {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: 0.25rem;
  }

  .responsive-table td.cell-description::before,
  .responsive-table td.cell-stacked::before,
  .responsive-table td[data-label="Description"]::before,
  .responsive-table td[data-label="Address"]::before {
    max-width: 100%;
  }

  .responsive-table td.cell-description .cell-value,
  .responsive-table td.cell-stacked .cell-value,
  .responsive-table td[data-label="Description"] .cell-value,
  .responsive-table td.cell-description {
    text-align: left;
    width: 100%;
    max-width: 100%;
  }

  .responsive-table td[data-label="Action"],
  .responsive-table td[data-label="Actions"] {
    justify-content: space-between;
    align-items: center;
  }

  .responsive-table td[data-label="Action"] .action-btn-group,
  .responsive-table td[data-label="Actions"] .action-btn-group {
    justify-content: flex-end;
    flex: 1;
    min-width: 0;
  }

  .audit-table th.col-audit-time,
  .audit-table td.col-audit-time,
  .audit-table th.col-audit-user,
  .audit-table td.col-audit-user,
  .audit-table th.col-audit-action,
  .audit-table td.col-audit-action,
  .audit-table th.col-audit-desc,
  .audit-table td.col-audit-desc {
    width: 100%;
    min-width: 0;
    white-space: normal;
  }
}

/* Small Smartphone Breakpoint (<= 480px) */
@media (max-width: 480px) {
  .main-content {
    padding: 0.85rem 0.5rem;
  }

  .sidebar {
    padding: 0.85rem 0.5rem;
  }

  .nav-menu {
    gap: 0.25rem;
  }

  .nav-link {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
  }

  .card-table {
    padding: 0.65rem;
    border-radius: 6px;
    margin-bottom: 1rem;
  }

  .responsive-table tr {
    padding: 0.65rem;
    margin-bottom: 0.65rem;
  }

  .responsive-table td {
    padding: 0.4rem 0;
    gap: 0.5rem;
    font-size: 0.82rem;
  }

  .responsive-table td::before {
    font-size: 0.68rem;
    max-width: 40%;
  }

  .btn-sm {
    padding: 0.25rem 0.45rem;
    font-size: 0.72rem;
  }

  .badge {
    font-size: 0.68rem;
    padding: 0.2rem 0.45rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
  }

  .stat-card {
    padding: 0.75rem;
  }

  .stat-value {
    font-size: 1.25rem;
  }
}

/* Ultra-Compact Smartphone Breakpoint (<= 390px, including 360px) */
@media (max-width: 390px) {
  .main-content {
    padding: 0.65rem 0.35rem;
  }

  .card-table {
    padding: 0.55rem;
  }

  .responsive-table tr {
    padding: 0.55rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
  }

  .stat-card {
    padding: 0.65rem;
  }

  .stat-title {
    font-size: 0.7rem;
  }

  .stat-value {
    font-size: 1.15rem;
  }
}

.badge-review-clear { background: rgba(34, 197, 94, 0.15); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.3); }
.badge-review-review { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-review-elevated { background: rgba(239, 68, 68, 0.2); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.4); font-weight: 600; }
.badge-entitlement { background: rgba(99, 102, 241, 0.15); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.3); }
.badge-historical { background: rgba(148, 163, 184, 0.2); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.4); font-weight: 600; }
